programming help in c please

Discussion in 'OT Technology' started by CXHatchback, Mar 13, 2003.

  1. CXHatchback

    CXHatchback Guest

    I really can't figure out how to do this. I'm supposed to be able to enter a string, then remove the vowels from it and print it on the screen. I don't think my code isthat complete, but right now it's not printing anything and I don't know why. Any help would be appreciated. Thanks

    //Homework 3 Problem 2

    char c,d,v;
    int i;

    #include <stdio.h>

    int isvowel(int);

    int main( void )
    {
    printf("Please type characters and press enter\n\n");
    c=getchar();

    for (c=1;c<=EOF;++c)
    {
    if (isvowel(c)==1)
    {
    c=' ';
    putchar(c);
    }
    else
    putchar(c);
    }
    return 0;
    }

    int isvowel(v)
    {
    if (v=='a' || v=='A')
    return 1;
    if (v=='e' || v=='E')
    return 1;
    if (v=='i' || v=='I')
    return 1;
    if (v=='o' || v=='O')
    return 1;
    if (v=='u' || v=='U')
    return 1;
    if (v=='y' || v=='Y')
    return 1;
    else
    return 0;
    }
     
  2. Fantik

    Fantik Guest

    String vowels ="aeiouAEIOU";
    String searchHere;
    String outputString;
    BufferedReader reader;
    reader = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("enter the word, yo: ");
    searchHere = reader.readLine();
    for (int i=0; i<searchHere.length(); i++)
    {
    if (searchHere.substring(i, i+1).indexOf(vowels)) >= 0)
    outputString = outputString + searchHere.substring(i,i+1);
    }

    System.out.println();
    System.out.println("The word with no vowels in it is this, yo: " + outputString);







    this wont help you at all, but it took me 1 minute and 30 seconds to write it in java.

    <3.
     
  3. BaZ

    BaZ 2004 ACC Champions

    Joined:
    Jun 12, 2001
    Messages:
    2,005
    Likes Received:
    0
    Location:
    Hokieville, USA
    because you dont have a printf anywhere in there except in the beginning
     
  4. kcarlson78

    kcarlson78 Meanwhile, Jesus continued to shake his head in ex

    Joined:
    Jun 27, 2002
    Messages:
    4,490
    Likes Received:
    0
    Location:
    Phoenix, AZ
    Code:
    //Homework 3 Problem 2
    
    char c,d,v;
    int i;
    
    #include <stdio.h>
    
    int isvowel(int);
    
    int main( void ) 
    	{
    	printf("Please type characters and press enter\n\n");
    	c=getchar();
    	
    	for (c=1;c<=EOF;++c)
    		{
    		if (isvowel(c)==1)
    			{
    			c=' ';
    			putchar(c);
    			}
    		else
    		putchar(c);
    		}
    	return 0;
    	}
    	
    int isvowel(v)
    	{
    	if (v=='a' || v=='A')
    	return 1;
    	if (v=='e' || v=='E')
    	return 1;
    	if (v=='i' || v=='I')
    	return 1;
    	if (v=='o' || v=='O')
    	return 1;
    	if (v=='u' || v=='U')
    	return 1;
    	if (v=='y' || v=='Y')
    	return 1;
    	else
    	return 0;
    	} 
    

    First of all... use code tags..
     
  5. kcarlson78

    kcarlson78 Meanwhile, Jesus continued to shake his head in ex

    Joined:
    Jun 27, 2002
    Messages:
    4,490
    Likes Received:
    0
    Location:
    Phoenix, AZ
    second.. why not use a string class.. and then deal with it as an array..

    or even sticking with the char data type.. make it an array..

    also it won't print anything b/c you don't have a statement to print anything except "printf("Please type characters and press enter\n\n");"
     
  6. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    Your code doesn't even come close to what you described it should do.

    c = getchar();

    You're reading one character into the variable c. If the user typed "Hello", you'd only have the 'H'. Look up how gets() works.

    for (c=1; c<EOF; ++c)
    {
    ...
    }

    Now, you're overwriting the single character that the user entered. You are then iterating over every ascii character, printing it to the screen if it's not a vowel, and printing a space if it is a vowel.

    Except, that it really won't do that because in your loop, you're reseting the loop counter (c = ' '). You'll reach the first vowel ('A' when c == 65), set c = ' ', print a space, then you're loop starts counting from c == 32 (space) again, so you're stuck in an infinite loop.

    Again, look up gets(), and then iterate only over the characters in the string.
     

Share This Page