Mathematics
 
 
MTH 568 - Compuational Science

 

Home
 

Syllabus
 

Course Outline
 

Resources
 

Contact Info


 
Input/Output in C



There are a variety of functions that control input and output in C.  Control characters are used to determine the format in which the output is displayed.
 
 

  • Input and Output from/to Console
    • printf("This is a statement to print\n");
    • scanf("%d", &data_item);

     
  • Input and Output from/to Files
    • Declaring a Data File
      • FILE *filepointer;

       
    • Opening a Data File
      • filepointer = fopen("filename", "w");

       
    • Output to a file
      • fprintf(filepointer, "%d", data_item);
      • fclose(filepointer);

       
    • Input from a file
      • fscanf(filepointer, "%d", &data_item);
      • feof(filepointer);

     
  • Control Characters
    • %d
    • %f
    • %lf
    • \n
    • \t
  • Example Code