Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: string

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Malaysia
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    string

    Dear sir,

    I an trying to write a function to return a nonzero if the character is a vowel, or zero if it is not a vowel. But, my program shown error message, why??? Below are my codes.

    #include <stdio.h>
    #include <conio.h>
    #include <ctype.h>
    #include <string.h>

    void isvowel(char string[]);

    void main(void)
    {
    char string[40];
    int idx;

    clrscr();

    gets(string);
    printf("%s", string);
    isvowel(string);

    getch();
    }

    void isvowel(char string[])
    {
    int idx;

    for (idx=0; string[idx] != '\0'; ++idx)
    { if (isvowel(string[idx]))
    putchar("<%c>", string[idx]);
    else
    putchar("%c", string[idx]);
    ++idx;
    }

    getch();
    }


    This is the actual output I wanted

    Washington (input)

    W<a>sh<I>ngt<o>n


    Thanks

    Xiang

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Why do you keep incrementing your variables before you use them?

    ++var != var++
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Dec 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's no need to increment your idx variable at the end of the for loop since it's in the update list. Also, change it from ++idx to idx++.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •