橘子味的心
标题:C库函数 fscanf()

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);

}

目录

分类