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

C programming : have a list of functions to implements but getting stuck in tryi

ID: 3682013 • Letter: C

Question

C programming : have a list of functions to implements but getting stuck in trying to develop them. They are:

Append(sentence) - a string including optional punctuation marks is sent as an argument for this command. In response to this command, the function appends the sentence argument to the end of the existing text stored on the system .

Delete(W)- In response to this command, the function must delete every occurence of the word passed through argument W in the text

Remove(target-sentence) - In response to this command, the function must delete the first occurence of the sentence passed through the argument target-sentence

search(A) - In response to this command, the function should search for the word passed through argument A and return the first setence conttaining this word.

count(S) - In response to this command, the function should return the number of times the word passed through argument S appears in the stored text

find(N) - In response to thus command, the function should return the Nth sentence stored on the system.

Please note the text is stored in memory and not on a text file that has to be opened first and function delete, remove,search, count and find should not work unless a setence has been appended. Initially the setenece has to be appeded to the empty space in memory. Sentences can be appended to the text numerous times before using the other functions as well as assume that calloc was use to the space for the text.

Explanation / Answer

main() { FILE *fsring1, *fsring2, *ftemp; char ch, file1[20], file2[20], file3[20]; printf("Enter name of first file "); gets(file1); printf("Enter name of second file "); gets(file2); printf("Enter name to store merged file "); gets(file3); fsring1 = fopen(file1, "r"); fsring2 = fopen(file2, "r"); if (fsring1 == NULL || fsring2 == NULL) { perror("Error has occured"); printf("Press any key to exit... "); exit(EXIT_FAILURE); } ftemp = fopen(file3, "w"); if (ftemp == NULL) { perror("Error has occures"); printf("Press any key to exit... "); exit(EXIT_FAILURE); } while ((ch = fgetc(fsring1)) != EOF) fputc(ch, ftemp); while ((ch = fgetc(fsring2) ) != EOF) fputc(ch, ftemp); printf("Two files merged %s successfully. ", file3); fclose(fsring1); fclose(fsring2); fclose(ftemp); return 0 }