|
发表于 2004-4-24 09:41:22
|
显示全部楼层
[php]
#include<stdio.h>
#include<string.h>
int main (int argc, char* argv[])
{
FILE* filename;
char buf[512];
char *p;
// open target file
if ( (filename = fopen(argv[1], "r")) == NULL ) {
printf("can't open file %s\n", argv[1]);
exit(1);
}
while ( fgets(buf, 512, filename) != NULL) {
p = strtok(buf, " ");
while ( p != NULL) {
if (!strcmp(p, "tall")) {
p= strtok(NULL, " ");
break;
}
else
p= strtok(NULL, " ");
}
if (p) printf("%s\n", p);
}
}
[/php]
运行结果:
[kj501@s2023 c]$ gcc temp.c
[kj501@s2023 c]$ ./a.out temp.txt
170
[kj501@s2023 c]$ |
|