(17) File, Global Variables, Search (Sina)

(17) File, Global Variables, Search (Sina) - Files, Global...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Files, Global Variables, Search Sina Meraji Fall 2009 Files # include <stdio.h> fopen( file_name , [mode] ); r open file for r eading w create file for w riting a open file fro a ppending Files # include <stdio.h> pointer_name = fopen( file_name , [mode] ); FILE * pointer_name ; Files # include <stdio.h> pointer_name = fopen( file_name , [mode] ); FILE * pointer_name ; Should be uppercase, it is a C macro Yes! It is a file pointer Choose any name you want Files # include <stdio.h> FILE * pointer_name = fopen( file_name , [mode] ); Another way.. Files # include <stdio.h> FILE * pointer_name = fopen( file_name , [mode] ); Returns NULL if the file cannot be opened for any reason Files # include <stdio.h> A standard way FILE * fptr ; if (( fptr = fopen( file_name , w ) == NULL ) printf(stderr, Cannot open %s\n , file_name ); Files # include <stdio.h> Do not forget to close it after you are done..! FILE * fptr ; fclose( fptr ); . . Process on the file . . if (( fptr = fopen( file_name , w ) == NULL ) printf(stderr, Cannot open %s\n , file_name ); Files # include <stdio.h> if (( fptr = fopen( file_name , w ) == NULL ) printf(stderr, Cannot open %s\n , file_name ); Use fprintf / fscanf to write/read on/from the file FILE * fptr ; fclose( fptr ); . . fscanf( fptr , Hello!\n ); ....
View Full Document

Page1 / 47

(17) File, Global Variables, Search (Sina) - Files, Global...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online