본문 바로가기
C 언어/0x05-file

file read

by SpeeDr00t 2016. 7. 12.
반응형

file read : 해당 파일을 읽어서 출력

1. 소스

include <stdio.h>

int main()
{
   int n;
   FILE *fptr;
   if ((fptr=fopen("test.txt","r"))==NULL){
       printf("Error! opening file");
       exit(1);         /* Program exits if file pointer returns NULL. */
   }
   fscanf(fptr,"%d",&n);
   printf("Value of n=%d\n",n);
   fclose(a);
   return 0;
}

2. 결과

hacker@HACKER:~/c$ gcc -o read1 read1.c

hacker@HACKER:~/c$ ./read1
Value of n=10
반응형

'C 언어 > 0x05-file' 카테고리의 다른 글

file open  (0) 2020.07.19