编程学习网为您整理以下代码实例,主要实现:C语言库fscanf()函数,希望可以帮到各位朋友。
//----------------------------
#include <stdio.h>
#include <stdlib.h>
int main () {
char str1[10], str2[10], str3[10];
int year;
file * fp;
fp = fopen ("file.txt", "w+");
fputs("We are in 2012", fp);
rewind(fp);
fscanf(fp, "%s %s %s %d", str1, str2, str3, &year);
printf("Read String1 |%s|\n", str1 );
printf("Read String2 |%s|\n", str2 );
printf("Read String3 |%s|\n", str3 );
printf("Read Integer |%d|\n", year );
fclose(fp);
return(0);
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!