Thread: Text processing. Deleting words not starting with vowels

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

    Text processing. Deleting words not starting with vowels

    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. Could you help me?

    Code:
    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':
    return1;
    default:
    return0;
    }
    }
    
    

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    You can make use of isupper(): isupper - C++ Reference

    If you want to discard whole words that start with something you don't like, you need to keep discarding until you hit the next space or newline (not sure what your file looks like), but it'll essentially be like this:

    while not EOF:
    read character
    if character is uppercase or is a vowel:
    keep reading characters until newline or space (while loop)
    else:
    keep reading characters until newline or space (while loop)
    copy character to output file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. text processing - huge amount of data
    By arian in forum C# Programming
    Replies: 3
    Last Post: 08-19-2015, 12:35 PM
  2. Text Processing!!
    By salmanriaz in forum C++ Programming
    Replies: 5
    Last Post: 12-17-2009, 06:21 PM
  3. text processing assignment
    By nellosmomishot in forum C Programming
    Replies: 28
    Last Post: 11-25-2008, 03:56 PM
  4. Replies: 4
    Last Post: 03-18-2008, 09:03 PM
  5. Deleting Text from a Text file
    By Daved in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2006, 09:47 PM

Tags for this Thread