给定文件:
用法
ac ab
ad am
av
al
ak aj an az ax
ag ah
我想从"am到an"读取,或者想在文件指针到达am时开始写入另一个文件,并保持写入,直到文件指针到达az。c.
#include <stdio.h>
#include <string.h>
#define WORD_SIZE 2
#define _S(x) #x
#define S(x) _S(x)
typedef enum { NO, YES } status;
int main(){
char word[WORD_SIZE + 1];
FILE *fin;
status Processing = NO;
fin = fopen("test.txt", "r");
while(1==fscanf(fin, "%" S(WORD_SIZE) "s", word)){
if(strcmp(word, "am")==0){
Processing = YES;
} else if(strcmp(word, "az")==0){
Processing = NO;
break;
}
if(Processing == YES){
fprintf(stdout, "%sn", word);
}
}
fclose(fin);
return 0;
}