Thread: Help with result only...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    23

    Help with result only...

    I did this program, he picks up a word and shows only the vowels,
    You input "house" hi show "oue"
    I want the result like this "o-u-e"

    Code:
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        
        char str[30],vogal[]={'a','e','i','o','u','A','E','I','O','U'} ,k[40];
        char a;
        int cont=0,i,qtd,aux=0;
     
         printf(" Digite uma palavra: ");
         fflush(stdin);
         scanf("%s",str); 
         qtd=strlen(str);     
         
     for(cont=0;cont<qtd;cont++)
       for(i=0;i<10;i++) 
        if(str[cont]==vogal[i])
          k[aux++]=str[cont];
          k[++aux]='0';     
               
     k[aux-1]=NULL;
     printf(" \n        %s ",k);
     getch();
    }

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You could add a - after each character you write. Then when you are done remove the last - by setting the final character to \0

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
     k[aux-1]=NULL;
    That is almost certainly not what you wanted to do. NULL is used to indicate zero in a pointer, not end of string. Either 0 or '\0' is what you want.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    23
    Quote Originally Posted by matsp View Post
    Code:
     k[aux-1]=NULL;
    That is almost certainly not what you wanted to do. NULL is used to indicate zero in a pointer, not end of string. Either 0 or '\0' is what you want.

    --
    Mats
    Thanks for the tip, but i still need the result like "a-e-i-o-u"

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Ervilha View Post
    Thanks for the tip, but i still need the result like "a-e-i-o-u"
    Yes, I understand.
    Code:
          k[aux++]=str[cont];
          k[++aux]='0';
    I take it you don't understand the difference between ++aux and aux++? One increments after the "use", the other before the "use". Also, is that '0' supposed to be '-' or '\0'. You should probably stick to EITHER ++aux or aux++ in both lines.

    Code:
    fflush(stdin);
    This is undefined, and should not be used [it may crash on a different system - fflush is only defined for output files in the C standard]. See the FAQ for "How do I clear the input buffer" if you need to do this in your code - but as far as I can tell, you actually want fflush(stdout) where you have it - if you need any fflush at all, that is.

    --
    Mats

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    An appropriate placed code, below, should solve your issue. I do believe matsp eluded to this as well.

    [code

    k[aux++] = '-';

    [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Need help with basic calculation program.
    By StateofMind in forum C Programming
    Replies: 18
    Last Post: 03-06-2009, 01:44 AM
  3. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  4. Can someone help with my seg fault?
    By John_L in forum C++ Programming
    Replies: 23
    Last Post: 03-01-2008, 04:04 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM