Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read a set of strings from the keyboard. Store the input strings to a file “stri

ID: 3768902 • Letter: R

Question

Read a set of strings from the keyboard. Store the input strings to a file “string.txt” in alphabet order. Please include the problem-solving process. You also need to handle all possible exceptions. it more like a text file. you have to read a strings from the keyboard. that all my instructor posted .he did not provide any other information apart what i sent you. for example you can enter janet, luis and put them in alphabetical order in a file. i hope this information helps you write the program thanks

Explanation / Answer

#include <stdio.h>
#include<string.h>

int main() {
   char s[5][20], t[20];
   int i, j;
   FILE *fptr;
   fptr=fopen("D:program.txt","w");
   if(fptr==NULL){
      printf("Error!");
      exit(1);
   }

   printf(" Enter any five strings : ");
   for (i = 0; i < 5; i++)
      scanf("%s", s[i]);

   for (i = 1; i < 5; i++) {
      for (j = 1; j < 5; j++) {
         if (strcmp(s[j - 1], s[j]) > 0) {
            strcpy(t, s[j - 1]);
            strcpy(s[j - 1], s[j]);
            strcpy(s[j], t);
          
         }
         }
   }

   for (i = 0; i < 5; i++)
      fprintf(fptr," %s", s[i]);
   fclose(fptr);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote