怎么用c语言读取word文件的内容啊,代码怎么写啊
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char ch;
char buffer[1024];//缓冲区
int len = 0;
FILE *fp;
fp=fopen("word.txt","r");
if(fp==NULL)
{
printf("open file word.txt failed!\n");
}
while(!feof(fp))
{
ch=fgetc(fp);
buffer[len++] = ch;//放到缓冲区
if (ch == '\n'){
buffer[len] = '\0';
printf ("%s", buffer);
len=0;
sleep(3);
}//回车输出
}
if (len){buffer[len] = '\0';printf ("%s", buffer);}//如果最后没有回车,输出缓冲区内容
fclose(fp);
return 0;
}
p = (“ 文件名”, “r”);
if(p == NULL)
{perror(“can not open the file”);
exit(EXIT_FAILURE);
}
。。。。。。
fclose(p); //关闭文档
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char ch;
char buffer[1024];//缓冲区
int len = 0;
FILE *fp;
fp=fopen("word.txt","r");
if(fp==NULL)
{
printf("open file word.txt failed!\n");
}
while(!feof(fp))
{
ch=fgetc(fp);
buffer[len++] = ch;//放到缓冲区
if (ch == '\n'){
buffer[len] = '\0';
printf ("%s", buffer);
len=0;
sleep(3);
}//回车输出
}
if (len){buffer[len] = '\0';printf ("%s", buffer);}//如果最后没有回车,输出缓冲区内容
fclose(fp);
return 0;
}
广告 您可能关注的内容 |