C语言怎打开一个有内容的文件啊?
#include<stdio.h>#include<stdlib.h>voidmain(){FILE*fp;char*filename="C:\\ProgramFiles...
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp;
char *filename = "C:\\Program Files\\Microsoft Visual Studio\\REDIST.TXT";
fp = fopen(filename,"r");
if(fp == NULL)
{
printf("File open error\n");
exit(0);
}
}
我错在哪呢?就是不显示文件的内容,望高手指教 展开
#include <stdlib.h>
void main()
{
FILE *fp;
char *filename = "C:\\Program Files\\Microsoft Visual Studio\\REDIST.TXT";
fp = fopen(filename,"r");
if(fp == NULL)
{
printf("File open error\n");
exit(0);
}
}
我错在哪呢?就是不显示文件的内容,望高手指教 展开
6个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp;
char ch;
char *filename = "C:\\Program Files\\Microsoft Visual Studio\\REDIST.TXT";
fp = fopen(filename,"r");
if(fp == NULL)
{
printf("File open error\n");
exit(0);
}
ch=fgetc(fp);
while(!feof(fp))
{
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}
#include <stdlib.h>
void main()
{
FILE *fp;
char ch;
char *filename = "C:\\Program Files\\Microsoft Visual Studio\\REDIST.TXT";
fp = fopen(filename,"r");
if(fp == NULL)
{
printf("File open error\n");
exit(0);
}
ch=fgetc(fp);
while(!feof(fp))
{
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询