Bläddra i källkod

mychomework

master
马也驰 2 år sedan
förälder
incheckning
7b37b5bb72
2 ändrade filer med 61 tillägg och 0 borttagningar
  1. +59
    -0
      lab1/10215501408.c
  2. +2
    -0
      lab1/10215501408.txt

+ 59
- 0
lab1/10215501408.c Visa fil

@ -0,0 +1,59 @@
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "math.h"
#include "string.h"
/**
* @brief generate a file consists of 50000 lines of words,
* half line has a substring "computer", and is repeated.
* the clone one is stripped of "computer".
*
* 0 ~ 9 : 48 ~ 57
* a ~ z : 97 ~ 122
*
*/
void file_create(const char *_addr)
{
FILE *file = fopen(_addr, "w");
size_t line = 250000u;
srand(time(NULL));
// char *str = NULL;
for (size_t i = 0; i < line; i++) {
// str = (char *)malloc(abs(rand())%20 * sizeof(char));
char str[abs(rand())%100+1];
for (size_t j = 0; j < strlen(str); j++) {
if (abs(rand()) % 2 == 0)
str[j] = abs(rand())%10 + 48;
else
str[j] = abs(rand())%26 + 97;
}
strcat(str, "computer\n");
fputs(str, file);
fputs(str, file);
// free(str);
}
fclose(file);
}
void file_show()
{
FILE *file = fopen("words.txt", "r");
int ch;
while ((ch = fgetc(file)) != '\n') {
printf("%c", ch);
}
fclose(file);
}
int main()
{
file_create("words.txt");
return 0;
}

+ 2
- 0
lab1/10215501408.txt Visa fil

@ -0,0 +1,2 @@
this is a file with the 10215501408.c

Laddar…
Avbryt
Spara