Question: Write a C program that reads in an input file. Display the input file and ask the user which word (the position of the word)

Write a C program that reads in an input file. Display the input file and ask the user which word (the position of the word) would you like to remove.

Ex:

You are a NARF! create a (very) simple word processor.

Enter position of word to delete(start counting at 0). Enter -1 to skip deletion:

The user will enter the value 3 to remove "NARF" from the sentence. The program will then tokenize the words in the sentence using strtok() and create a new sentence without the chosen word using strcat(). It will then write this new sentence to an output file. The removes words for each sentenece will be saved in a separate array, which will be printed out at the end of the program.

Here is my code so far, I'm not sure how to do the rest:

#include

#include

#include

int main()

{

FILE *in;

FILE *out;

in = fopen("Lab6_bad.txt", "r");

out = fopen("Lab6_good.txt","w");

char *line = malloc(sizeof(char)*100); // allocating size

while(fgets(line,100,in))

{

fprintf(out, "%s", line);

printf("%s ", line);

}

printf("Which word (as a position) would you like to remove from the line ");

printf("Start counting at 0. Enter -1 to skip ");

int position;

scanf("%d", &position);

fclose(in);

fclose(out);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!