Portál AbcLinuxu, 26. října 2025 02:25
void read_file (FILE *fr, char *what){
char input[512];
int what_len = strlen(what);
int line = 0; //Counter of lines.
int num = 0;
/*Reading a text file line by line.*/
while (fgets(input, 512 , fr) != NULL){
line++;
char *where = input;
/*Checking an occurrence of searched string.*/
while ((where = strstr(where, what))) {
where += what_len;
num++;
} //End of WHILE
/* Value num > 0 Indicates an occurrence of searched string so that a message for a user can be printed.*/
if (num > 0) {
printf("Searched string '%s' is found %d times on line %d\n", what, num, line);
num = 0; //Initial position for the next checking must be 0.
} //End of IF
} //End of WHILE
fclose(fr);
} //End of the function 'read_file'
int main(){
char *what = "do";
FILE *fr;
fr = fopen("text.txt","r");
read_file(fr, what);
return 0;
}
Řešení dotazu:
while [ "$(ls -l test.txt | awk '{ print $5 }')" -lt "20000000000" ]; do cat nejaky_kratky_dokument.txt >>test.txt done
dd if=/dev/zero of=10MiB.files bs=1048576 count=1010MiB random (o kus pomalejší):
dd if=/dev/urandom of=10MiB.files bs=1048576 count=10Stačí jen upravit 10 na 20480 a je 20GiB files.
Na súbore plnom núl mu asi jeho fgets() bude platné ako popolník na motorke.A to prečo?
-D_FILE_OFFSET_BITS=64
-D_FILE_OFFSET_BITS=64.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.