热门

最新

红包

立Flag

投票

同城

我的

发布
carry_jidong
carry_jidong
4 年前
truecarry_jidong

C语言中第八章重定向有个程序用VS编写可能需要改一下,这是我编写的结果:
//打开文件并读取文件内容
/*#include <stdio.h>
#include <stdlib.h> // for exit()
int main()
{
int ch;
FILE* fp;
char fname[50]={0}; // to hold the file name

printf("Enter the name of the file: ");
scanf_s("%s", fname,50);
fopen_s(&fp, fname, "r"); // open file for reading
if (fp == NULL) // attempt failed
{
printf("Failed to open file. Bye\n");
exit(1); // quit program
}
// getc(fp) gets a character from the open file
while ((ch = getc(fp)) != EOF)
putchar(ch);
fclose(fp); // close the file
return 0;
}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条动态
立即登录