Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:16:57+00:00 2026-06-10T09:16:57+00:00

My task is to write a program which is supposed to omit a single

  • 0

My task is to write a program which is supposed to omit a single word after a specific sequence in the previous ones.
I’ve already prepared a working getword procedure (returns char *), now I only have problems with main where I have the following snippet of code, which allows me to detect where should I remove the word. But I don’t know how to actually omit/remove that word from the outfile.

int main(int argc, char **argv)
{
    FILE *infile = NULL, *outfile = NULL;
    char *word = NULL;
    int c;
    int yes = 0;
    int counter = 0;

    /* completely irrelevant - opening, writing to files, error messages etc. */
    while (1) {
        c = fgetc(infile);

        word = getword(infile);
        if (counter == 2) {
            counter = 0;
            yes = 0;
                    /* here it should somehow omit the word */
            continue;
        }
        if (choose(word, strlen(word))) {
            fputs(word, outfile);
            counter++;
            yes = 1;
        } else {
            fputs(word, outfile);
            if (yes == 1) {
                counter--;
            }   
        }
        free(word); 
    }
    /* completely irrelevant */
}   

EDIT: Added to clarify

“getword just reads a word, it doesn’t perform any check whether it is the word I’m looking for. main() does that check. When the if (choose) is satisfied then it means that word contains sequence of letters I’m looking for, and the second word after that particular word should be omitted. Variables “counter” and “yes” may not be the perfect algorithm, but at first I want it to work, then I’ll try to simplify that. “Counter” counts up to 2 to determine which word is to be omitted, and “yes” helps to increment the counter after we move to a word not satisfying if (choose) condition.”

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:16:58+00:00Added an answer on June 10, 2026 at 9:16 am

    I got it, in the place of

    /* here it should somehow omit the word */

    there should be free(word);

    Everything works like charm.
    I got it earlier, but forgot to post answer to my own question 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The task is to write a program which prompts for a filename and then
I have task to write program allowing users to draw stars, which can differ
I have an interesting task: to write a program which captures input from the
I have a task to write a program which handles the division by zero
I have another task for my school and it is: Write a program which
I have been assigned wit the task to write a program that takes a
My task is to write an app(unfortunatly on C) which reads expression in infix
My task is to write a class RFind which recursively searches the current directory
I need to write a program which does 2 tasks at the same time
I need to write a program that displays a PDF which a third-party supplies.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.