Need some help / C language / Deleting vowel words

The task is to delete all vowel words. I would be glad if you could help me. Something is wrong with the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <math.h>
#include <cstdio>

int trink (char);

int main ()
{
    FILE* read_me = fopen("tekstas.txt", "r");
    if (!read_me)
    printf ("Reikiamas failas nerastas!");
    FILE* write_me = fopen("trinkbalses.txt", "w"); 
    char c;

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

            }
            {
                fputc(c, write_me);
            }
    }
    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;
}
}
Last edited on
Something is wrong with the program.

This is certainly one of those things (lines 17 and 23)
 
    if(c == ' ' || '\t' || '\n' )

Each condition must be typed in full:
 
    if (c == ' ' || c == '\t' || c == '\n' )


Line 23 is more tricky for two reasons. There is a function call, which should be done just once, and the condition is != rather than ==.


Last edited on
Could you help me to rewrite it????

Its working, but deleting just first vowels
Last edited on
Line 23, something like this:
 
    while ((c=fgetc(read_me)) && !(c == ' ' || c == '\t' || c== '\n')) {} 


Can you explain what the program is supposed to do please. Is it to ignore any word which contains a vowel at any position? Well, that would mean almost all words. Not sure what is intended.
The program should ignore vowel words (when first letter is vowel).
The highest while is not working properly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)
                {

                    c=fgetc(read_me);
                    fprintf(write_me, "/");
                    do {fprintf(write_me, "");} while((c=fgetc(read_me)) == ' ' || c == '\t' || c == '\n' );

                }

            }
            {
                fputc(c, write_me);
            }
    }
There's not a lot I can say without posting actual code, and I think the point here is to think about what needs to be done in order to achieve the required result.

My test data Input:
If I was a blackbird, I'd whistle and sing
And I'd follow the ship that my true love sails in
And on the top riggings, I'd there build my nest
And I'd pillow my head on his lily white breast

I am a young maiden and my story is sad
For once I was courted by a brave sailor lad
He courted Josephine strongly by night and by day
But now my dear sailor is gone far away
and the output:
was blackbird, whistle sing
follow the ship that my true love sails 
the top riggings, there build my nest
pillow my head his lily white breast

young maiden my story sad
For was courted by brave sailor lad
He courted Josephine strongly by night by day
But now my dear sailor gone far 


The way I looked at it was this. Not only does the word starting with a vowel need to be omitted, but also any trailing spaces which follow that word. Otherwise the output looks strangely formatted with too many spaces. But the newline character should always be output, even if it follows a vowel word.

The actual programming logic - well each person will have their own approach. In my attempt, the main while loop contained three blocks (controlled by if/else if/else) to handle
1. whitespace,
2. a whole word starting with a vowel and its trailing spaces,
3. and lastly a whole word which doesn't start with a vowel.






Topic archived. No new replies allowed.