Formatted String I

Formatted String I - Formatted String I/0 There are two...

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

View Full Document Right Arrow Icon
Formatted String I/0 There are two formatted string I/O operations: int sscanf(s, " format ", arguments ) int sprintf(s, " format ", arguments ) #define N sizeof(int) +sizeof(double)+6 int i; double d; char *s;
Background image of page 1

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

View Full Document Right Arrow Icon
9: Line Oriented String I/0 char* fgets(char *buf, int n, FILE *in); reads a line from the file in , and stores it in the block pointed to by buf . Stops reading when: - n-1 characters have been read - end-of-line has been encountered; ( \n is stored at the end of buf ) - end-of-file has been encountered. In any case, buf is always properly terminated ( \0 is stored). The function returns buf if successful and NULL if no characters have been read or there has been a reading error. Often it is useful to rewrite the end-of-line character:
Background image of page 2
Read a Line (at most n-1 characters) from a File if(fgets(buffer, n, f) == NULL) error
Background image of page 3

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

View Full Document Right Arrow Icon
longest line /* find the length of the longest line; at most max */ long longest(const char *fname, const int max) {
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 12

Formatted String I - Formatted String I/0 There are two...

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

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