C
#include <stdio.h>int main(void){FILE *fp; // Pointer to the file to be readFILE* fout; // Pointer to the file to be writtenint numfruits = 12; // There are 12 fruits listed in fruits.txtchar myFruits[numfruits][256]; // Each fruit name has a length smaller than 256char myFruitsReversed[numfruits][256];int i, j; // Needed for loopingint indexEnd, count; // Needed for reversing strings// Open both files in the appropriate read or write modefp = fopen("fruits.txt", "r");fout = fopen("output/outfile.txt", "w");// Exit if there's an error opening either of the filesif (fp == NULL){printf("There was an error opening fruits.txt\n");return 1;}else if (fout == NULL){printf("There was an error opening the file output/outfile.txt\n");return 1;}else{// Loop and on step i, read the i^th string into the arrayi = 0;while (!feof(fp)){fscanf(fp, "%s\n", &myFruits[i]);i++;}// For each string, find its size, reverse it and write it outfor(i = 0; i < numfruits; i++){// Count the number of characters in the stringj = 0;count = 0;while(myFruits[i][j] != 0){count++;j++;}// Reverse the i^th string that was readj = 0;indexEnd = count - 1;while(j < count){myFruitsReversed[i][j] = myFruits[i][indexEnd];j++;indexEnd--;}//Insert a null character at the end of the reversed stringmyFruitsReversed[i][j]='\0';// Write out the reversed stringfprintf(fout, "%s \n", myFruitsReversed[i]);}// Close both file streamsfclose(fp);fclose(fout);}return 0;}