Thread: Deleting vowel words C programming

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    2

    Deleting vowel words C programming

    With this while program should ignore vowel words in the text, but its deleting just first two letters. Could you help me?

    Code:
    while ((c=fgetc(read_me)) != EOF && c != EOF)
        {
            if (c == ' ' || c == '\t' || c == '\n' )
                {
                    fputc(c, write_me);
                    c=fgetc(read_me);
                    if(trink(c) == 1)
                    {
    
    
                        do {c=fgetc(read_me); fprintf(write_me,"");} while((c=fgetc(read_me)) == ' ' || c == '\t' || c == '\n' );
    
    
                    }
    
    
                }
                {
                    fputc(c, write_me);
                }
        }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The basic problem is you're reading input in several places. If the input character doesn't match your expectation, your program logic becomes broken.

    Consider the idea of implementing a finite state machine.
    Finite-state machine - Wikipedia

    Eg.
    Code:
    bool inWord = false;
    while ( (c=fgetc(read_me)) != EOF ) {
      if ( inWord && isspace(c) ) {
        // were processing a word, and the next char is space
        inWord = false;
      }
      else if ( !inWord && isalpha(c) ) {
        // found first character of a word
        inWord = true;
      }
    }
    There is a single point in the code which fetches the next character.
    You then use state variables to decide what to do with it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text processing. Deleting words not starting with vowels
    By Ignas Kalnietis in forum C Programming
    Replies: 1
    Last Post: 10-30-2016, 10:48 AM
  2. Repeat vowel Problem?
    By Khwarizm in forum C Programming
    Replies: 6
    Last Post: 06-09-2014, 12:52 PM
  3. Replies: 10
    Last Post: 01-11-2014, 03:48 PM
  4. WAP to remove vowel string using Pointer and Function
    By Pallav Mahamana in forum C Programming
    Replies: 6
    Last Post: 01-28-2013, 02:26 PM
  5. Replies: 3
    Last Post: 01-29-2011, 04:54 AM

Tags for this Thread