1 / 14

C programing language

C programing language. Chapter 7 : Input and Output Present by Le Thi Hien. Contents . Standard Input and Output Variable-length Argument List Formatted Output Formatted Input File Access Error Handling Line Input and Output. Standard Output and Input.

phyre
Download Presentation

C programing language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C programing language Chapter 7 : Input and Output Present by Le ThiHien

  2. Contents • Standard Input and Output • Variable-length Argument List • Formatted Output • Formatted Input • File Access • Error Handling • Line Input and Output

  3. Standard Output and Input • Standard input (stdin) : data going into a programe. typical from keyboard. • Standard output (stdout): the stream where a program writes its output data.

  4. Standard Input and Output Standard input/ output can be substituted by • File : Input :Prog <infile Output :Prog >outfile Example : • ./a.out >result.c • ./a.out <result.c • Pipeline : Otherprog | prog Prog | anotherprog

  5. Variable-length Argument Lists • Need #include<stdarg.h> • va_listtype • Macro : • va_start(va_listap, lastfix); • va_arg(va_listap, type); • va_end(va_listap); • Syntax : type name (arg1,…); • Example : void minprintf(char *fmt,…) { va_listap; va_start(ap, fmt);/*ap point to 1st unnamed arg*/ … case ‘d’ : ival = va_arg(ap, int); … va_end(ap); }

  6. Fomatted Output

  7. Formatted Input

  8. Formats

  9. Formats

  10. File Access • FILE *fopen (const char* name, char *mode); • intfclose(FILE* fp); • Example : Ex1 : FILE* fp; fp = fopen(“mytext.txt”, “r”); Ex2 : stdin stdout stderr • Type FILE * • Constant.

  11. File Access

  12. File Access

  13. stderr • Why need stderr ? • intferror(FILE *fp); /*check error indicator. If error indicator is set, return non-zero value. Otherwise, return 0.*/ • intfeof(FILE *fp); /*check EOF indicator. If EOF indicator is set, return non-zero value. If not, return 0.*/

  14. Thank you !

More Related