Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C that will read the file that was created by the previous exercise, and retrieve the strings one at a time

Write a program in C that will read the file that was created by the previous exercise, and retrieve the strings one at a time in reverse sequence and write them to a new file in the sequence in which they were retrieved. For example, the program will retrieve the last string and write that to the new file, then retrieve the second to last and retrieve that from the file, and so on, for each string in the original file.

Here is the previous file:

#include

#include

int main() {

char temp[100];

printf("Enter file name: ");

scanf("%s", temp);

FILE *fp = fopen(temp, "w");

if(fp) {

printf("Enter as many strings as you want(quit to quit) ");

while(gets(temp) != NULL) {

if(strcmp(temp, "quit") == 0) {

break;

}

fprintf(fp, "%s ", temp);

}

fclose(fp);

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions