求助,c语言简单问题
代码如下
#include<stdio.h>
#include<pthread.h>
#include<ctype.h>
pthread_mutex_t counter_clock = PTHREAD_MUTEX_INITIALIZER;
static int total_words=0;
int main(int ac , char *av[]){
void *count_words(void*);
if(ac!=3){
printf("Useage:%s file1 file2 \n",av[0]);
exit(1);
}
int error1,error2;
pthread_t thread1,thread2;
error1 = pthread_create(&thread1, NULL, count_words, av[1]);
error2 = pthread_create(&thread2, NULL, count_words, av[2]);
pthread_join(thread1,NULL);
pthread_join(thread2,NULL);
printf("%d\n",total_words);
}
void *count_words(void* f){
char *filename=(char*)f;
FILE *fp;
int c,prevc='\c';
if((fp=fopen(filename,"r"))!=NULL){
while((c=getc(fp))!=EOF)
{
if(!isalnum(c)&&isalnum(prevc)){
pthread_mutex_lock(&counter_clock);
total_words++;
pthread_mutex_unlock(&counter_clock);
}
prevc=c;
}
fclose(fp);
}
else {
perror(filename);
}
return NULL;
}
这是一个多线程统计单词个数的程序,具体代码不重要,我就是想问问这一行
if((fp=fopen(filename,"r"))!=NULL){
当我把双引号改成单引号时就会出现Segmentation fault (core dumped)的错误,但我上网好像看到也有使用单引号的,求大神解答,谢谢