免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4494 | 回复: 8
打印 上一主题 下一主题

为什么会出现不可以识别的文件格式呢 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-22 11:11 |只看该作者 |倒序浏览
#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都是英文的.

论坛徽章:
0
2 [报告]
发表于 2007-10-22 11:18 |只看该作者
gdb不是那么用的............

论坛徽章:
0
3 [报告]
发表于 2007-10-22 11:27 |只看该作者
gcc -g test.c -o test
gdb test
至于之后的操作,man gdb

论坛徽章:
0
4 [报告]
发表于 2007-10-22 13:33 |只看该作者

回复 #2 baohuaihuai 的帖子

那怎么用呢

论坛徽章:
0
5 [报告]
发表于 2007-10-22 13:34 |只看该作者

回复 #3 ruoyisiyu 的帖子

我那个程序需要命令行参数的呀,那怎么用呀

论坛徽章:
0
6 [报告]
发表于 2007-10-22 13:41 |只看该作者
原帖由 zenglei286 于 2007-10-22 13:33 发表
那怎么用呢


先gdb ./1
进去了之后用
r 1.txt 2.txt

论坛徽章:
0
7 [报告]
发表于 2007-10-22 13:47 |只看该作者
那为什么一运行就停不下来呢

论坛徽章:
0
8 [报告]
发表于 2007-10-22 13:51 |只看该作者
你得先设断点,然后单步.还要涉及到进入特定的线程调试.
man gdb吧

论坛徽章:
0
9 [报告]
发表于 2007-10-22 16:08 |只看该作者

回复 #6 baohuaihuai 的帖子

谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP