-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrandomStringGenerator.c
More file actions
55 lines (47 loc) · 1.28 KB
/
randomStringGenerator.c
File metadata and controls
55 lines (47 loc) · 1.28 KB
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
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *outputFile = fopen("input2.html", "w");
FILE *inputFile = fopen("inputOptions.txt", "r");
if(inputFile == NULL){
printf("input file could not be found");
exit(1);
}
if(outputFile == NULL){
printf("input file could not be found");
exit(1);
}
char pattern[250];
long long length = 0;
fgets(pattern, 250, inputFile);
printf("enter the length of the file ");
scanf("%d", &length);
printf("\n");
if (length<0){
printf("enter a valid length");
exit(2);
}
int occurenceCounter = 0;
int random = 32 + rand()%95;
for(int i = 0; i<length; ){
if(rand()%10){
if (random != 60 && random != 62){
putc( random , outputFile );
random = 32 + rand()%95;
i++;
}
else{
random = 32 + rand()%95;
i++;
}
}
else{
for(int j = 0; pattern[j] != NULL; j++){
putc(pattern[j], outputFile);
}
occurenceCounter++;
i++;
}
}
printf("number of occurences of the pattern are %d\n", occurenceCounter);
}