⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 9-23.txt

📁 C++完美演绎 经典算法 如 /* 头文件:my_Include.h */ #include <stdio.h> /* 展开C语言的内建函数指令 */ #define PI 3.141
💻 TXT
字号:
/* 范例:9-23 */
#include <stdio.h>
#include <stdlib.h>
void main(int argc,char *argv[])
{
  FILE *fp1;
  int pos;

  if((fp1=fopen(argv[1],"w"))==NULL)
  {
    printf("File Open Error!\n");
    exit(1);
  }
  fputs("abcdefg",fp1);
  fputs("\n0123456",fp1);
  fclose(fp1);
  /* 可擦写(更新) */
  if((fp1=fopen(argv[1],"r+"))==NULL)
  {
    printf("文件打开错误\n");
    exit(1);
  }

  pos = fseek(fp1,4,0); 	/* 从文件头跳4bytes */
  putc(65,fp1);
  printf("pos = %d\n",pos);

  fseek(fp1,6,2); 	/* 从文件尾跳6bytes */
  putc('#',fp1);
  fseek(fp1,3,1); 	/* 从目前位置跳3bytes */
  putc('@',fp1);

  fclose(fp1);
}

程序执行结果:(假设输出文件名out)
D:\TC>p9-23 out
pos = 0

D:\TC>type out	=> 检查文件out内容
abcdAfg
0123456      #   @

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -