遍匈 / C囂冱炎彈垂 / stdio.h /

C囂冱rewind()痕方?繍猟周峺寞嶷仟峺?猟周蝕遊

遊猟周?#include <stdio.h>

rewind()痕方喘噐繍猟周峺寞嶷仟峺?猟周議蝕遊?揖扮賠茅才猟周送屢購議危列才eof炎芝?屢輝噐距喘fseek(stream, 0, SEEK_SET)?凪圻侏泌和?
void rewind(FILE * stream);

‐歌方/stream葎參嬉蝕猟周議峺寞。

廣吭?彈鳩議傍?宸戦議峺寞音頁猟周峺寞stream?遇頁猟周坪何議了崔峺寞?昧彭斤猟周議響亟猟周議了崔峺寞?峺?輝念響亟忖准??朔卞強。遇猟周峺寞頁峺?屁倖猟周?泌惚音嶷仟験峙猟周峺寞音氏個延。

猟周峺寞FILE *stream嶄?淫根匯倖響亟了崔峺寞char *_nextc?万峺?和匯肝猟周響亟議了崔。凪潤更泌和?
typedef struct
{
 int _fd; // 猟周催
 int _cleft; // 産喝曝嶄複和議忖准方
 int _mode; // 猟周荷恬庁塀
 char * _nextc; // 和匯倖忖准議了崔
 char * _buff; // 猟周産喝曝了崔
}FILE;
耽輝序佩匯肝響亟朔?乎峺寞徭強峺?和匯肝響亟議了崔。輝猟周胡嬉蝕賜幹秀扮?乎峺寞峺?猟周議蝕兵了崔。辛參喘痕方ftell()資誼輝念議了崔峺寞?匆辛參喘rewind()/fseek()痕方個延了崔峺寞?聞凪峺?俶勣響亟議了崔。

‐糞箭/響函猟周議方象朔壅指欺蝕遊嶷仟響函。
#include<iostream.h>
#include<stdio.h>
void main(void)
{
 FILE* stream;
 long l;
 float fp;
 char s[81];
 char c;
 stream = fopen("fscanf.txt","w+");
 if(stream == NULL)/*嬉蝕猟周払移*/
 {
 printf("the file is opeaned error!\n");
 }
 else/*撹孔夸補竃佚連*/
 {
 fprintf(stream,"%s %ld %f %c","a_string",6500,3.1415,'x');
 fseek(stream,0L,SEEK_SET); /*協了猟周響亟峺寞*/
 fscanf(stream,"%s",s);
 printf("%ld\n",ftell(stream));
 fscanf(stream,"%ld",&l);
 printf("%ld\n",ftell(stream));
 fscanf(stream,"%f",&fp);
 printf("%ld\n",ftell(stream));
 fscanf(stream," %c",&c);
 printf("%ld\n",ftell(stream));
 rewind(stream);/*峺?猟周蝕遊*/
 fscanf(stream,"%s",s);
 printf("%s\n",s);
 fclose(stream);/*購液送*/
 }
}
塰佩潤惚?
8
13
22
24
a_string

殻會枠幹秀匯倖猟周亟秘匯乂方象?隼朔聞喘feeek痕方協了猟周峺寞欺猟周蝕遊幟倖響函方象?響函頼穎朔聞喘rewind痕方繍猟周議響/亟峺寞嶷仟協了欺猟周議蝕遊?壅肝響函扮窟孖響函議頁蝕遊議忖憲a_string。

嗽泌?委匯倖猟周議坪否?塋菖敍祖刺錬?⇒j姥間撞汁輌燦氅勅顗?
#include "stdio.h"
void main()
{
 FILE *fp1, *fp2;
 fp1 = fopen("file1.c", "r"); // 坿猟周
 fp2 = fopen("file2.c", "w"); // 鹸崙欺file2.c
 while(!feof(fp1)) putchar(fgetc(fp1)); // ?塋承銃祖刺?
 rewind(fp1); // fp指欺蝕兵了崔
 while(!feof(fp1)) fputc(fgetc(fp1), fp2);
 fclose(fp1);
 fclose(fp2);
}

AltStyle によって変換されたページ (->オリジナル) /