各位高手求救了???
迦叶123 2006-05-31 06:56:12 下面的代码实现:把TXT文件的路径以参数形式给出,把文件中出现的单词写在一个三维字符数组中。
各位大侠给检查一下错误。
#include <stdio.h>
#define YES 1
#define NO 0
#define filnum 10
#define wornum 10
char *del[] = {"is","are","there","be"};
void main(int argc,char*argv[])
{
char num[filnum][wornum][10];
int inword,i,j,m;
int words;
char c;
FILE *fp;
for(i = 1;i <= argc-1;i ++)
{
words = -1;
j = 0;
inword = NO;
if((fp = fopen(argv[i],"r")) == NULL)
{
printf("can't open file:%s",argv[i]);
exit(0);
}
while( ! feof(fp))
{
c = fgetc(fp);
if(c == ' ' ||c == '\n' ||c == '\t')
{
inword = NO;
if(words != -1)num[i][words][j] = '\0';
}
else if (inword == NO)
{
inword = YES;
words = words + 1;
num[i][words][j ++] = c;
}
if(inword == YES)num[i][words][j ++] = c;
}
}
fclose(fp);
printf("%s\n",num[0][0]);
getch();
}