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 8504195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:57:37+00:00 2026-06-11T01:57:37+00:00

So for a lab at uni… Ive been challenged to find all words in

  • 0

So for a lab at uni… Ive been challenged to find all words in the usr/share/dict/linux.words
file using fopen, fgets etc with every vowel only once, in order.

i.e. facetious

So far I have the following code… but its flawed somewhere…

int all_vowels( char *s )
{ 
    const unsigned char *p = (const unsigned char *)s;

    char *v = malloc(sizeof(char *));
    char *vowel = v;

if(*p == '\0') return -1;

while( *p != '\0' )
{    
        if( *p == 'a' || *p =='e' || *p =='i'|| *p =='o' || *p =='u' )
        {
            *v = *p;
            v++;
        }
        p++;
    }


    if ( *vowel == 'a' && (*vowel + 1) == 'e' && (*vowel + 2) == 'i' && (*vowel + 3) ==     'o' && (*vowel + 4) == 'u' ) 
    { 
        return 1; 
    }

    return -1;
}

int main (int argc, char *argv[])
{    
    FILE *file;
    char line[BUFSIZ];

    if (( file = fopen("/usr/share/dict/words", "r") ) == NULL) 
    {
        fprintf(stderr, "cannot open %s\n", "/usr/share/dict/words");
        exit(1);
    } 

    while ( !feof(file) )
    {
        fgets(line, sizeof(line), file);
        if ( all_vowels(line) == 1 )
        {
            printf("%s\n", line);
        }
    }
    fclose(file);
    return 0;

}

Any tips would be great!!!

Im really confused at the moment…

  • 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-11T01:57:38+00:00Added an answer on June 11, 2026 at 1:57 am

    You are accessing v as if it were pointing to a location holding a number of characters, when indeed you only reserve space for one single char * (usually 4 byte on a 32 bit machine and 8 byte on a 64 bit machine):

    char *v = malloc(sizeof(char *));
    

    That might or might not be enough for what you are trying to store in it; in your case, the number of vowels, in any given word.

    Whenever possible, you should avoid dynamic allocations; in your case, you don’t need them, you can declare an array of fixed size instead of a char*:

    char v[5];
    

    In addition to that, you have to check if you have read 5 vowels already, so that you don’t exceed the array size; if, after 5 vowels, you encounter another one, you can stop the check anyway; the currently encountered one has to be a duplicate vowel, the word will therefore not qualify.

    The way you address characters is also a problem. Check again what * does: it dereferences the expression immediately to the right. In your case, it will always dereference v, then add something to it (which is also legal, since the result of dereferencing is a char). So if the first character where v points to is an a, the second an e, then *v will yield 'a', (*v + 1) will yield 'b', (*v +2) will yield 'c' and so on – you see, the result is an addition to the letter a by the given number; it doesn’t matter at all what comes after the first character because you never access the value there. To achieve what you want with pointer arithmetic, you’d have to use parenthesis: *(v+1) – i.e., add 1 to the pointer v, then dereference it. This would yield the second character in the c string starting at v, i.e. 'e'.
    Note that with v declared as above you can simply write v[0], v[1], v[2] and so on to address each character.

    Aside from that, check the last comparison in your if condition, you had an ‘e’ instead of an ‘u’ there.

    By the way, as a side note, and something to think about: There is a solution to your problem which does not require the v/vowel variables at all… only a single integer variable!

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

Sidebar

Related Questions

I'm using a serial terminal to provide input into our lab experiment. I found
so I've been working on a project on the university lab computers, and I
I am having trouble with this simple loop for a uni lab. It wont
I took my first 'fundamentals of programming' lab session at uni today. One thing
In a Java SWT lab I had previously, it talks about using Composites then
I am using Paypal lab Integration wizard to put express checkout work on my
My task in this lab is to accept multiple input file and the format
I've been working on a lab for school and everything was going swimmingly until
I'm writing some SQL for our lab, and I have it all done except
In an information security lab I'm working on, I've been tasked with executing multiple

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.