-
Notifications
You must be signed in to change notification settings - Fork 0
/
pw.c
64 lines (49 loc) · 920 Bytes
/
pw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "pw.h"
int main (int args, char *argv[]) {
//define variables
char line[15];
int length, error;
//code
length = 0;
if(args >= 2) {
printf("error at input to many arguments \n");
return -1;
}
printf("max number is 2^32 -1 \n ");
fgets(line, sizeof(line), stdin);
error = sscanf(line, "%d", &length);
if (error == -1) {
printf("error at input");
}
working(length);
}
void working(int length) {
//define variables
int i;
char toOut[length + 1];
//code
for(i = 0; i < length; i++) {
toOut[i] = randomCharacter();
}
toOut[length] = (char) 0;
printf("\n %s \n", toOut);
}
char randomCharacter() {
//define variables
int cache;
int found;
//code
found = 0;
while(found == 0) {
srand(clock());
cache = rand();
cache = cache % 128;
if (cache > 33 && cache < 94) {
found = 1;
}
if (cache > 96 && cache < 126) {
found = 1;
}
}
return (char) cache;
}