怎样用C语言写一个程序,打开记事本,并输入一段文字

求程序。。。谢谢
2024-12-05 06:22:09
推荐回答(2个)
回答1:

#include
#include

#define Line 1024

int main()
{
//文件名及文件指针
char infile[]="D:\\Wtmp\\1.txt";
char outfile[]="D:\\Wtmp\\2.txt";
FILE *fpi,*fpo;

//暂存器
char *outbuf;
outbuf = (char *)malloc(Line*sizeof(char));

if( ( fpi=fopen(infile,"扰慧r") ) == NULL )
{
printf("文件打开%s失败\n",infile);
return 3;
}
if( ( fpo=fopen(outfile,"w") ) == NULL )
{
printf("文件打开%s失败\n",outfile);
return 3;
}

while(1)
{
//outbuf要干缓肆答净
//memset(outbuf,0,Line);
outbuf=0;

fprintf(fpo,"%s",outbuf);
if (fgets(outbuf,Line,fpi)==NULL)
{
break;
}//雹孙全部行结束退出循环

//DelStr(outbuf,"删除字符串"); //重载函数DelStr
//DelStr(outbuf,"要替换字符串","替换成字符串"); //重载函数DelStr
fprintf(fpo,"%s",outbuf);
}

//关闭文件
free(outbuf);
fclose(fpi);
fclose(fpo);
return 0;
}

回答2:

先向一个文本文件里写入你想要输入的文燃燃字,然后调用记事本打开这个文件

#include
#include <哪慧process.h>

void main()
{
FILE *pFile = fopen("a.txt", "w");
char str[] = "你想要输入的字符串";
fwrite(str,1, sizeof(str)/sizeof(str[0]), pFile);
fclose(pFile);
system("notepad a.txt"皮缓虚);
}