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:

  • [C] fputs & fgets Purpose : Remove —–BEGIN CERTIFICATE—– —–END CERTIFICATE—– and copy to file.txt C code #include <stdio.h> #define Max_CA_String 128 int… Read More
  • [C] Coding skill - !!x "!!x" 這樣就可以保證不管 x 的輸入是什麼,最終輸出只有 0 或 1 #include<stdio.h> int main() { int x=0x00; int y=0x0a; printf("x = %d",!!x); printf("y = %d"… Read More
  • [C] Implement - thread qemu-thread.c /* * Wrappers around mutex/cond/thread functions * * Copyright Red Hat, Inc. 2009 * * Author: * Marcelo Tosatti <mtosatti@re… Read More
  • [C] Insert work in front of string && Debug it Compile following code gcc -Wall -g -Og c.c #include<stdio.h> static char * no_prefix (const char *s) { static char buffer[1024]; static… Read More
  • [C] The concept of C Get the concept about Array is not a pointer, but array can convert to pointer automatically. (原創) array和pointer一樣嗎? (C/C++) (C) * –> value… Read More

0 意見:

張貼留言