Initial commit

This commit is contained in:
caskd 2020-01-23 17:13:51 +01:00
commit cc8beab255
No known key found for this signature in database
GPG Key ID: 79DB21404E300A27
6 changed files with 132 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
binary
CMakeCache.txt
CMakeFiles
cmake_install.cmake
Makefile
*.png
*.swp

9
CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.0)
project(programmingquest LANGUAGES C)
SET(CHALLANGE namegen)
add_executable(binary
src/${CHALLANGE}.c
)

24
src/fizzbuzz.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#define LIM 100
int main(void) {
for (int i=1; i<LIM; i++) {
int f=!(i%3),b=!(i%5);
if (f || b) {
if (f) {
printf("Fizz");
if (b) {printf(" ");}
}
if (b) {
printf("Buzz");
}
} else {
printf("%i", i);
}
if (i<LIM-1) {
printf(", ");
}
}
printf("\n");
return 0;
}

53
src/namegen.c Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NICKLIM 36
int main(int argc, char argv[]) {
srandom(time(NULL));
char name[NICKLIM+1];
if (argc==1) {
fprintf(stderr,"Please enter your occupied nickname: \n");
char c;
int pos=0;
while ((c=getchar())!='\n' && pos<NICKLIM+1) {
name[pos++] = c;
}
name[pos] = '\0';
} else {
fprintf(stderr,"You have to send your username via standard input.\n");
return 2;
}
if (name[0]=='\0') {
fprintf(stderr,"No name given, generating one...\n");
int c, len;
for (c=0, len=15; c<len; c++) {
unsigned int uppercase=random()%2;
char start = 'a';
if (uppercase) {
start = 'A';
}
name[c] = start + (random()%26);
}
name[++c] = '\0';
}
for (int c=0; c<NICKLIM+1 && name[c]!='\0'; c++) {
if (random()%2) {
switch (name[c]) {
case 'o': case 'O': name[c] = '0'; break;
case 'i': case 'I':
case 'l': case 'L': name[c] = '1'; break;
case 'z': case 'Z': name[c] = '2'; break;
case 'e': case 'E': name[c] = '3'; break;
case 'a': case 'A': name[c] = '4'; break;
case 's': case 'S': name[c] = '5'; break;
case 'g': case 'G': name[c] = '6'; break;
case 't': case 'T': name[c] = '7'; break;
case 'b': case 'B': name[c] = '8'; break;
}
}
}
fprintf(stderr, "Randomly generated name: ");
printf("%s\n", name);
return 0;
}

24
src/passwordgen.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[]) {
srandom(time(NULL));
if (argc > 1) {
char generated[atoi(argv[1])+1];
int i;
for (i=0; i<=atoi(argv[1]); i++) {
char start = 'a';
if (random()%2) {
start = 'A';
}
generated[i] = start + random()%26;
}
generated[i] = '\0';
printf("%s\n", generated);
} else {
fprintf(stderr, "Too few arguments.\n");
return 1;
}
return 0;
}

15
src/ringbuffer.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#define BUFSIZE 64
int main(void) {
char buffer[BUFSIZE] = {'\0'}, c;
int i=0;
while ((c=getchar())!=EOF) {
buffer[i++]=c;
if (i==BUFSIZE-1)
i=0;
printf("Buffer is now: %s\r", buffer);
}
printf("\n");
return 0;
}