2013年1月16日 星期三

[C Language] How to use C to read file and print it


[C Language] How to use C to read file and print it



#include <unistd.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define PATH "./happy.txt"



void main(){



  char line;

  FILE *inFilePtr;



  inFilePtr = fopen(PATH, "r+");



  while (!feof(inFilePtr)){

     fscanf(inFilePtr, "%s", &line);

     printf("%s\n", &line);

  }



}



Output :



one

two

three

four

 



Reference :



Related Posts:

0 意見:

張貼留言