写了一个读入文本并输出文本长度的小程序,可是结果非常奇怪,求助。
完整的应该是一个统计关键词数量的程序,刚做了个开头,就出现了个各种调不懂的问题。。。
这个运行之后能正常输出文本内容到屏幕上,但是输出文本长度的时候总是“1637148”,不知道怎么回事,希望大家能帮助我搞定它。。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <graphics.h>
#include <string.h>
#define LEN 16
#define MAXLEN 10000
char str[MAXLEN];
int next[LEN];
void main()
{
char author[LEN];
char word1[LEN];
char word2[LEN];
char word3[LEN];
char file[1000];
int len;
printf("请输入作家姓名\n");
scanf("%s",author);
printf("请输入特征词1\n");
scanf("%s",word1);
printf("请输入特征词2\n");
scanf("%s",word2);
printf("请输入特征词3\n");
scanf("%s",word3);
printf("请输入文件位置,包括后缀名\n");
scanf("%s",file);
FILE *fp;
if((fp=fopen(file,"r"))==NULL)
{
printf("读取错误\n");
exit(1);
}
printf("\n");
int j=0;
char ch;
while((ch=fgetc(fp))!=EOF)
{
str[j]=ch;
j++;
}
//str[i]='/0';
printf("%s",str);
fclose(fp);
len=j;
printf("%d\n",&len);
}