Working with files

Joined
Dec 10, 2021
Messages
4
Reaction score
0
Hello help please

there is a text file, I want to remove from it all sentences ending with an exclamation mark.
I only did what removes the mark itself, how do I remove the whole sentence?

C:
#include <stdio.h>
#include <stdlib.h>
 
    int main(void)
    {
        int c = 0;
        const unsigned char discard = '!';
        const char *file_name = "ex1.txt";
        FILE *input_file = NULL, *output_file = NULL;
    
        if (!(input_file = fopen(file_name,"r")) || !(output_file = fopen("ex2.txt","w")))
        {
           fprintf(stderr,"error handling");
            exit(EXIT_FAILURE);
        }
    
        while ((c = fgetc(input_file)) != EOF)
        {
            if (c != discard)
            {
                fputc(c,output_file);
            }
        }
 
        fclose(input_file);
            
        exit(EXIT_SUCCESS);
    }
 
Joined
Mar 3, 2021
Messages
241
Reaction score
30
You'll need to start keeping track of the start of sentences. Define all punctuation characters. If you find a punctuation and it's not an exclamation mark, output from your beginning-of-sentence location and the current one. If the punctuation is an exclamation mark, just don't output it. In either case, update your beginning-of-sentence to the point after the punctuation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top