The National Computer Grade examination two level course-C Language Programming _ 16th _ file

Source: Internet
Author: User

Example 16.1

Output the text entered from the keyboard as-is to a file named File_a.dat, with the character @ as the keyboard input end flag.

(1) Open the file.

(2) Enter a character from the keyboard.

(3) Determine if the input character is @. If so, end the loop and perform step (7).

(4) Output the characters you have just entered into the specified file.

(5) Enter a character from the keyboard.

(6) Repeat steps (3) to (5).

(7) Close the file.

(8) End of procedure.

1#include <stdio.h>2#include <stdlib.h>3 4 Main ()5 {6FILE *fpout;7     Charch;8     if(Fpout = fopen ("File_a.dat","W")) ==NULL)9     {Tenprintf"Can ' t open this file!\n"); OneExit0); A     } -CH =GetChar (); -      while(ch! ='@') the     { - FPUTC (CH, fpout); -CH =GetChar (); -     } + fclose (fpout); -}

Example 16.2

Outputs the contents of a File_a.dat text file on an existing disk to the terminal screen as-is.

(1) Open the file.

(2) reads a character from the specified file.

(3) Determine if the read-in is the end-of-file flag. If so, end the loop and perform step (7).

(4) Output the characters just entered to the terminal screen.

(5) read one more character from the file.

(6) Repeat steps (3) to (5).

(7) Close the file.

(8) End of procedure.

1#include <stdio.h>2#include <stdlib.h>3 4 Main ()5 {6FILE *Fpin;7     Charch;8     if(Fpin = fopen ("File_a.dat","R")) ==NULL)9     {Tenprintf"Can ' t open this file!\n"); OneExit0); A     } -CH =fgetc (fpin); -      while(ch! =EOF) the     { - Putchar (CH); -CH =fgetc (fpin); -     } + fclose (fpin); -}

123

The National Computer Grade examination two level course-C Language Programming _ 16th _ file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.