- 论坛徽章:
- 0
|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <ctype.h>
int total_words = 0;
main(int ac , char * av[ ])
{
pthread_t t1, t2;
void *count_words(void *);
if(ac!=3){
printf("usage: % s file1 file2\n", av[0]);
exit(1);
}
printf("ss");
pthread_create(&t1,NULL,count_words,(void *)av[1]);
pthread_create(&t1,NULL,count_words,(void *)av[2]);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
printf("%5d: total words\n", total_words);
}
void *count_words(void *f)
{
char *filename = (char * )f;
FILE *fp;
int c, temp, prevc = '\0';
if((fp = fopen (filename, "r" )) != NULL)
{
while((c = getc(fp))!= EOF)
{
if(!isalnum(c)&& isalnum(prevc))
{
temp=total_words;
sleep(0.1); /*延时,使产生脏数据*/
total_words=temp+1;
}
prevc =c;
}
fclose(fp);
}
else
perror(filename);
return NULL;
}
然后我运行了 gcc -g -o 1 -lpthread lib5-1.c
都没有问题,然后运行后./1 1.txt 2.txt 就不会停下来,也没有出现什么字符,我用gdb ./1 1.txt 2.txt 又说我1.txx不可识别文件格式
is not a core dump
1.txt与2.txt都是英文的.
|
|