请问一个对文件操作的有关问题,将文件的信息取出放在数组里面!

请教一个对文件操作的问题,将文件的信息取出放在数组里面!!
请教一个对文件操作的问题,将文件的信息取出放在数组里面!!
有文本文件内容如下:  
20070101001  
20070102001  
20070502552  
20070012554  
20075522111  
.
.
.
将其信息逐行取出放在数组里面


------解决方案--------------------
[quote]1.
printf( "Total Records:%s ",str[20]);
[/quote]你确定这样可行?你要输出第21个str串?还是第21个str中的字符?根据你的定义[quote]char str[20];[/quote]只能达到第二种结果
[quote]2.
printf( "Enter The Province to search: ");
[/quote]这句我不知道你用来干什么的,或者是没有用到,反正你后继的函数中没有读取键盘的输入,可能是你还没有做ba。
quote]3.
r=pro;
while(*p!=32)
{
*r=*p;
r++; p++;
}
*r=0;
[/quote]
[quote]
*r=0;
[/quote]你想给字符串加个结尾是 "\0 ",而不是0概念弄清。其他的比如包了string又不用之类的就另说了
------解决方案--------------------
#include <stdio.h>
//#include <string.h>
#include <malloc.h>
#include <conio.h>

int SeekNum(FILE *fp,char **str);

int main()
{
FILE *fp;
char *fname= "record.txt ";
char str[20][12]; //.... 根据你上面数据的格式改称了20个12位的数组
fp=fopen(fname, "rt ");
if(!fp)
{
printf( "cann 't open the file %s\n ",fname);
getch();
return 0;
}

//printf( "Enter The Province to search: "); //.... 暂时无用

int count=SeekNum(fp,str);
for(int i=0;i <count;i++) //.... 修改成循环输出字符串数组
{
printf( "Total Records:%s\n ",str[i]);
}
getch();
return 0;
}

int SeekNum(FILE *fp,char **str)
{
char *line,*p,pro[20],*r;
int cont;

line=(char*)malloc(80);
cont=0;

while(!feof(fp))
{
fgets(line,80,fp);
p=line;

r=pro;
while(*p!=32)
{
*r=*p;
r++; p++;
}
*r= '\0 '; //.... 添加字符串终结符

strcpy(str[cont],pro); //.... 改成了读入str[]的数组中
cont++;
}

return cont;
}


改完大概就这样了,在公司里,没有编译器,基本的语法和细节就这样了。自己试试吧