Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am reading content from a file to be read into a char array in C. How could I delete words which are uppercase // or which start with a non-vowel? I really cant understand how to save the last c ==> how to check if you have space before vowel.

int main ()
{
    FILE* read_me = fopen("x.txt", "r");
    if (!read_me)
    printf ("NERA");
    FILE* write_me = fopen("y.txt", "w");
    char c;
    while ((c=fgetc(read_me)) != EOF && c != EOF)
    if(trink(c) == 0)
    {
        fputc(c, write_me);
    }
    {
        XXX
    }
    fclose (read_me);
    fclose (write_me);
}

int trink (char w)
{
    switch(w) {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
      return 1;
    default:
      return 0;
}
}


What I have tried:

XXX part is unknown. Could you help me to sove this problem.
Posted
Updated 27-Oct-16 10:18am
Comments
Chris Maunder 27-Oct-16 14:32pm    
Forget coding for a moment, have you tried solving this on paper?

Yes indeed, in my opinion I should find a vowel and if we have space before it its TRUE, when we skip everything till other space. And this process continuous
 
Share this answer
 
Comments
jeron1 27-Oct-16 15:23pm    
How about find a space then check to see if there is a vowel after?
Member 12819728 27-Oct-16 15:57pm    
But how to check if there is a vowel after?
jeron1 27-Oct-16 16:45pm    
Read the next character (provided there is one). See CPallini's post for a good and straight forward suggestion. Coding will another matter though, based on what you posted. Go in small increments if possible and use a debugger to see what your program is doing. It is difficult at best, to debug your code without one.
A simple solution would be using a variable containing current state as either
  1. Processing a valid word.
  2. Processing blanks.
  3. Processing a to-be-skipped word.

Then, based on current state and next char, your program could establish correctly what to do.
 
Share this answer
 
Comments
Member 12819728 28-Oct-16 3:07am    
I cannot understand how to check next char, without destroying system
jeron1 28-Oct-16 10:10am    
Destroying system how? You have a state, based on the character you just read. You read the next character and decide what to do based on the state. Once you've decided what to do and processed that character, you see if the state needs to be changed. Then the process starts over by reading the next character.
Member 12819728 30-Oct-16 8:41am    
Could you help me to finish that code?
jeron1 31-Oct-16 10:47am    
Kind of sounds like you're not understanding the algorithm involved. Perhaps write pseudocode (not terribly detailed or code dependent) first or create a flow chart, then try and code it up.

0. Set state = PROCESSING_BLANKS.
1. Read character.
a. If state == PROCESSING_BLANKS, (if not go to #2)
a. is character == BLANK?, if so go back to #1
b. is character == VOWEL? if so set state == PROCESSING_VALID_WORD, go back to #1.
c character is not a vowel, set state to PROCESSING_WORD_TO_BE_SKIPPED, go back to #1.

2. If state == PROCESSING_VALID_WORD, if not go to #3.
a. is character == BLANK, if so write the character out and set state to PROCESSING_BLANKS, go back to #1.
b. if character != BLANK, write it out, go back to #1.

You can probably figure the rest, note that the go to lines can be accomplished using loop and conditional constructs. The use of goto's tend to be looked down upon as their overuse can make code difficult to read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900