求:编写对C源程序加行号的程序,执行格式:ADD file_name

来源:百度知道 编辑:UC知道 时间:2024/06/07 19:51:37
求各位大大,文件的不会做。2周要交。其实文件就没学就给我们做,这我也看不懂,原题就是这样的
这些都没要求,要是能做出加就加吧。谢谢了先 。因为文件没教懂的不多,题目也就这么写的,能做出来就行

已在vs2005和dev-cpp下编译通过,结果正确:
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
FILE *fsource, *ftarget; /*两个文件指针分别指向源文件和目标文件*/
int ln;
char line[256],source[30],target[30];
printf("Please input source file name and target file name:\n");
gets(source);
gets(target);
/*fopen打开源文件失败的处理*/
if((fsource=fopen(source,"rt"))==NULL){
printf("Can't open source file %s.\n",source);
getch();
exit(1);
}
/*fopen打开目标文件失败的处理*/
if((ftarget=fopen(target,"wt"))==NULL){
printf("Can't open target file %s.\n",target);
getch();
exit(1);
}
ln=1;
/*从源文件中逐行读出内容并在前面加上行号写入目标文件直到文件结束*/
while(fgets(line,256,fsource)!=NULL) /*逐行读源文件*/
if (fprintf(ftarge