2、从指定文件(a1.txt)位置写入指定个数汉字演示程序ST2.C。

程序代码如下:

#include "stdio.h"

#include "string.h"

main()

{

FILE *fp;

int i,k;

char ch[81]={"\0"},filename[13];

printf("请输入文件名:");

scanf("%s",filename);

fp=fopen(filename,"r+");

if(fp==NULL)

{printf("打开文件出错\n");

return(0);

}

printf("从第几个汉字开始写入:");

scanf("%d",&i);

printf("请输入写到文件的汉字:");

scanf("%s",ch);

fseek(fp,2*(i-1),0);

fwrite(ch,1,strlen(ch),fp);  (1)

fclose(fp);

}

  我的电脑

关闭