In-Class Practice

Files


Change the following program to read the information from a file named input.dat and to write the information to a file named output.dat.

 // Name Input and Output
 //
 #include <stdio.h>
 #include <string.h>
 #define MN 10
 #define MC 30
 #define FM "30"

 int main(void)
 {
         char name[MN][MC+1];
         int i, n, goOn = 1;

         printf("Enter names (^ to stop)\n");
         n = 0;
         do {
                 printf("? ");
                 scanf(" %"FM"[^\n]", name[n]);
                 if (strcmp(name[n], "^") == 0)
                        goOn = 0;
                 else if (n < MN - 1)
                        n++;
                 else
                        goOn = 0;
         } while(goOn != 0);

         for(i = 0; i < n; i++)
             printf("%s\n", name[i]);

         return 0;
 }

Show your code here

 // Files - Name Input and Output
 //
 #include <stdio.h>
 #include <string.h>
 #define MN 10
 #define MC 30
 #define FM "30"

 int main(void)
 {
         char name[MN][MC+1];
         int i, n;                                 


























         return 0;
 }



   Printer Friendly Version of this Page print this page     Top  Go Back to the Top of this Page



  Designed by Chris Szalwinski   Copying From This Site   

Creative Commons License