-
Notifications
You must be signed in to change notification settings - Fork 0
/
week4_generate_random_input.c
54 lines (50 loc) · 1.17 KB
/
week4_generate_random_input.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct book{
char name[100];
char author_name[100];
char publication[100];
int edition;
int ISBN_number;
int price;
int publication_year;
};
void rand_input(FILE * fp,int n){
char alpha[26];
int i,j;
srand(time(NULL));
strcpy(alpha,"abcdefghijklmnopqrtsuvwxyz");
int length;
char space=' ';
char newline='\n';
for(i=0;i<n;i++){
length=rand()%20+1;
for(j=0;j<length;j++){
fprintf(fp,"%c",alpha[rand()%26]);
}
fputc(space,fp);
length=rand()%20+1;
for(j=0;j<length;j++){
fprintf(fp,"%c",alpha[rand()%26]);
}
fputc(space,fp);
length=rand()%20+1;
for(j=0;j<length;j++){
fprintf(fp,"%c",alpha[rand()%26]);
}
fputc(space,fp);
fprintf(fp,"%d %d %d %d",rand()%10000,rand()%10000,rand()%10000,rand()%10000);
fputc(newline,fp);
}
}
int main()
{
FILE * fp;
fp=fopen("sample.txt","w");
int n;
scanf("%d",&n);
rand_input(fp,n);
return 0;
}