utopia_xu

C语言文件操作

0
阅读(639)
/*------------------------------------------------------------------------
*name:
*fuction:   d:\\codeblock\\a中写入字符串,然后在显示出来
*other:
*version:
*author:xu沫尘
*description:
*time:2017-3-14
------------------------------------------------------------------------*/
#include"stdio.h"
void  main()
{
    FILE *fp;//定义指向一个文件的指针
    char ch;
    if((fp=fopen("d:\\codeblock\\a\\string","wt+"))==NULL)//写入电脑的位置d:\\codeblock\\a
    {
      printf("\ncann't open file strike any key exit!");
      getch();
      exit(1);
    }
    printf("input a string:\n");
    ch=getchar();
    while(ch!='\n')
    {
        fputc(ch,fp);
        ch=fgetchar();
    }
    rewind(fp);
    ch=fgetc(fp);
    while(ch!=EOF)
    {
    putchar(ch);
    ch=fgetc(fp);
    }
    printf("\n");
    fclose(fp);
//system("pause");//加上
他之后,批组建生产的exe文件执行到最后不会自动关闭
}