【发布时间】:2016-11-23 08:42:07
【问题描述】:
#include<stdio.h>
void hello(FILE * fp)
{
if( ( fp = fopen("log","r") ) == NULL)
printf("%s", "Error opening file");
}
void main()
{
char p;
FILE *sf=fopen("prac.txt","r");
hello(sf);
p=fgetc(sf);
printf("%c",p);
}
我想通过hello函数将文件指针sf更改为指向文件log,但printf仍在打印prac.txt文件的内容。
【问题讨论】:
-
您的
hello需要第二个参数,例如string filename -
你的代码是纯C,我去掉了C++标签。 C 和 C++不是同一种语言
标签: c