#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> int main() { FILE *FpSource; char *str="012345678567890000"; int TestOk=0; long fpi=0; char ch; clrscr(); if((FpSource=fopen("e:\\bc31\\number.txt","w"))==NULL) { printf("Can not open the file!"); exit(0); } fwrite(str,strlen(str),1,FpSource); fclose(FpSource);
if((FpSource=fopen("e:\\bc31\\number.txt","r+"))==NULL) { printf("Can not open the file!"); exit(0); } rewind(FpSource); while(((ch=fgetc(FpSource))!=EOF)&&(TestOk==0)) { str[0]=str[1]; str[1]=str[2]; str[2]=str[3]; str[3]=ch; fpi++; if((str[0]=='5')&&(str[1]=='6')&&(str[2]=='7')&&(str[3]=='8')) TestOk=1; } if(TestOk) { printf("\nOK%d",fpi); str[0]='4';str[1]='4';str[2]='4';str[3]='4'; fseek(FpSource,fpi-4l,0); fwrite(str,4,1,FpSource); } fclose(FpSource); if((FpSource=fopen("e:\\bc31\\number.txt","r"))==NULL) { printf("Can not open the file!"); exit(0); } fread(str,fpi,1,FpSource); printf("\nstr=%s",str); fclose(FpSource); getch(); return 0; }
这个,看看可以么!!!随机数自己加!!!
[此贴子已经被作者于2004-11-16 15:22:46编辑过]
差点把你忘了...