Txt r fscanffptr d icqnumber printficq dn

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: ", "r") fscanf(fptr, "%d", &ICQnumber) printf("ICQ = %d\n", ICQnumber) fclose(fptr) return 0 } /* close the file */ c:ntestncontact.txt 12345678 ICQ = 12345678 Just to give you some idea. Don't attempt to understand it now! CSC 1500 { Lecture 99 5 Opening Files Function Prototype: | fopen() #include <stdio.h> FILE *fopen(char *filename, char *mode) Function Description: Opens the le named by filename in the way speci ed by the character string mode which has the following meanings: Mode Description "r" "w" "a" "r+" "w+" "a+" Open for reading Truncate to zero length or create for writing Append open for writing at end-of- le, or create for writing Open for update (reading and writing) Truncate or create for update Append open or create for update at end-of- le Return Values: fopen() returns a non-NULL pointer (of type FILE *, usually referred to as a stream) if the le can be opened successfully. Otherwise, a NULL pointer is returned. Example: FILE *fp if ((fp=fopen("data.txt", "r"))==NULL) { printf("Cannot open file.\n") exit(0) } CSC 1500 { Lecture 99 6 Reading From Files | fscanf() Function Prototype: #include <stdio.h> int fscanf(FILE *fp, format_specifier, arg1, ...) Function Description: Similar to the use of scanf(), except that the data comes from the stream fp (instead of from the standard input). Advances the \ le stream" associated with fp. To avoid confusion, the te...
View Full Document

This note was uploaded on 05/23/2010 for the course COMPUTER S CSC1500 taught by Professor Fung during the Spring '10 term at CUHK.

Ask a homework question - tutors are online