关于C语言中读取文件的问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 22:45:40
用c语言把记事本a.txt的第三行写在b.txt文件当中
a.txt
1 123 54 676
455 78 8 8
6777 56
最好用c,不要用c++,各位大侠,谢谢了。
一楼能不能说详细些?谢了。

程序是完整的也符合你的要求了,就是还有一点输出问题。你看看,再适当改一改我想就可以了。见谅不能继续帮你写了啊。
#include<stdio.h>
#define N 75
int a[N][N];
void input(int m,int n)
{
int i,j=-1;
FILE *fp1,*fp2;
if((fp1=fopen("a.txt","r"))==0)
{
printf("Can't open this file!!!");
exit(0);
}
fp2=fopen("b.txt","w");
for(i=0;i<m;i++)
{
do
{
j++;
fread(&a[i][j],sizeof(int),1,fp1);
}while(a[i][j]!='\0');

}
for(i=0;a[n-1][i]!='\0';i++)
printf("%d\t",a[n-1][i]);

}
main()
{
int m,n;
printf("Please input the low of the file and your low:");
scanf("%d%d",&m,&n);
input(m,n);
}

打开文件(文件类型指针指向文件相对路径),r+打开
fgets()函数读取
将串存入三个顺序结构里(类似数组,是字符串型的)
输出第三个数组
用w+写入文件

FILE *fpa = fopen("a.txt", "