当前位置: 代码迷 >> C语言 >> [求助]fgets函数使用请教
  详细解决方案

[求助]fgets函数使用请教

热度:288   发布时间:2007-07-10 00:34:36.0

#include<stdio.h>
#include<string.h>

void main()
{
FILE *in = NULL;
char *p = NULL;
char xx[3][3] = {0, };
int i = 0;

//打开in.dat文件,该文件中有两行数据,第一行为11,第二行为22
in = fopen("in.dat","r");

//第一次调用fgets函数
p = fgets(xx[0],4,in);
printf("\nxx[0] = %s",xx[0]);
printf("\np1 points: %x\n",*p);
printf("\np1 Value: %x\n",p);
printf("\np1 Address: %x\n",&p);

//第二次调用fgets函数
p = fgets(xx[0],4,in);
printf("\nxx[0] = %s",xx[0]);
printf("\np2 points: %x\n",*p);
printf("\np2 Value: %x\n",p);
printf("\np2 Address: %x\n",&p);

*p = NULL;
fclose(in);
};

[此贴子已经被作者于2007-7-10 0:35:17编辑过]


----------------解决方案--------------------------------------------------------
你这个可以证明什么?

你去看看fgets 的返回值返回的什么!

[此贴子已经被作者于2007-7-10 2:05:17编辑过]


----------------解决方案--------------------------------------------------------

你自己好好想想吧
in指针不变 你那22那里来的 你的换行是那里来的?
从已开始你那程序和问题就是错误的
#include<stdio.h>
#include<string.h>
void main()
{
FILE *in;
char xx[3][3];
int i = 0;
//打开in.dat文件,该文件中有两行数据,第一行为11,第二行为22
in = fopen("in.txt","r");//、我把这里改成TXT了
//第一次调用fgets函数
fgets(xx[0],4,in);
printf("%d\n",*in);
//第二次调用fgets函数
fgets(xx[0],3,in);
printf("%d\n",*in);
fclose(in);
};

[此贴子已经被作者于2007-7-10 2:18:30编辑过]


----------------解决方案--------------------------------------------------------