Thread: isvowel() included in ctype for C lang?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    76

    isvowel() included in ctype for C lang?

    I know its available in C++, but when I compile, I'm getting ERROR: Undefined symbol: .isvowel. Am I doing something wrong(probably the case) or what else could be wrong?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    isvowel() is not part of the C standard. You would have to write your own routine.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Here's one:
    Code:
    int isvowel(int ch)
    {
      int c = toupper(ch);
    
      return (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    }
    That's the way I'd do it anyway Unless 'Y' also counts...
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    76
    Ok what I'm trying to do is count the number of vowels in a string. This is what I have so far:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    int vowelcount(char text);
    int digitcount(char *text);
    
    int main() {
    	
    	int x, y, d, size;
    	char v, text[81];
    
    	printf("Please type a string or hit 'Enter' to quit:\n");
    	fgets(text, 81, stdin);
    
    	while (text[1]!='\0') {
    		size=strlen(text)-1;
    		printf("count=%d\n", size);
    		d=digitcount(text);
    		printf("digit=%d\n", d);
    		y=vowelcount(text);
    		printf("vowel=%d\n", y);
    
    
    
    
    
    		printf("Please type a string or hit 'Enter' to quit:\n");
    		fgets(text, 81, stdin);
    	}
    return 0;
    }
    
    
    int vowelcount(char text) {
    
    	int y;
    	char v;
    
    	y=0;
    	v=toupper(text);
    
    	if (v == 'A' || v == 'E' || v == 'I' || v == 'O' || v == 'U')
    		y++;
    
    	return y;
    }
    
    int digitcount(char *text) {
    	
    	int x, d;
    	
    	d=0;
    	
    	for(x=0;text[x]!='\0';x++)
    		if(isdigit(text[x]))
    			d++;
    	
    	return d;
    }
    I keep gettting a "Function argument assignment between types "unsigned char" and "unsigned char*" is not allowed."Should I be using a for loop like this for(x=0;text[x]!='\0';x++)befoire the if statement in the function vowelcount? Any help?

  5. #5
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Been a while since I been here...

    how this for a start..

    Code:
    #include <stdio.h>
    
    void removeblanks(char *s);
    
    int main(void)
    {
    	  char first[80];
    	  char second[80];
    
    	  printf("Enter the string:\n");
    	  gets(first);
    	  removeblanks(first);
    	  puts(second);
    
    
    
      return 0;
    }
    
    void removeblanks(char *s)
    {
    	int *t = 0;
    	while(*s != '\0')
    	 {
    		if (*s != ' ')
    
    		  *t++ = *s;
    
    		t++;
    		s++;
    	 }
    	 *s = '\0';
    }
    I know it removes blanks but can you see some possiblities..

    I hope you do...like reading in a string, checking the string, etc...

    Mr. C: Author and Instructor

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    76
    I understand some of your program, but what is *t++ = *s;?

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It has the effect of setting *t equal to *s and then incrementing t.
    If you understand what you're doing, you're not learning anything.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Mister C
    how this for a start..
    Code:
    	  gets(first);
    Please, God, no.

    Most worrisome is your title when I see this.

    [edit]
    Code:
             *t++ = *s;
    Given t's initialization, this is dereferencing a NULL pointer, which is most certainly undefined behavior.
    Last edited by Dave_Sinkula; 11-19-2004 at 11:27 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I wanted to use isvowel( ) in c++ but was unhappy to find it wasn't available.. so I just wrote my own which uses the cascading property of switch/case



    c++ code
    Code:
    bool is_vowel(const char& input)
    {
    	switch(toupper(input))
    	{
    		case 'A': 
    		case 'E':
    		case 'I':
    		case 'O':
    		case 'U': return true;	
    
    		default:  return false;
    	}
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  10. #10
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    But that is C++, not C.
    Itsme86's solution is a nice one, though.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  11. #11
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by nizbit
    Ok what I'm trying to do is count the number of vowels in a string. This is what I have so far:
    Code:
    .........................................
    	while (text[1]!='\0') {
    		size=strlen(text)-1;
    		printf("count=%d\n", size);
    		d=digitcount(text);
    		printf("digit=%d\n", d);
    		y=vowelcount(text); //<<-- look here
    		printf("vowel=%d\n", y);
    ................................
    	}
    return 0;
    }
    
    int vowelcount(char text) { //<<-- look here
    ..................................
    }
    I keep gettting a "Function argument assignment between types "unsigned char" and "unsigned char*" is not allowed."
    It's all there. You're sending a string (char*) to a function that receives a single char. It should be
    Code:
    y=vowelcount(text[index]);
    Second you have a infinite loop...
    Third, declare a variable to control the cicle and index the string. At the end of the cicle increment it. When text[index]=='\0' end cicle.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > int vowelcount(char text) {
    Use the same code you have for digitcount

    > if (v == 'A' || v == 'E' || v == 'I' || v == 'O' || v == 'U')
    And put this line inside a new function called isvowel()


    @Mister C
    > how this for a start..
    It sucks big time - using gets(), uninitialised variables, NULL pointers, dubious type conversions
    I'm really tempted to just mod your post out of existence, just in case someone sees your title and thinks it's credible code.

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I believe we had fun covering isvowel here a while back.

    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Registered User
    Join Date
    Oct 2004
    Posts
    76
    I'm just all screwed up. This is just kicking my arse. Now I really like I don't know what I'm doing. I can't use switch case because it was not covered. I'm just trying to count how many vowels are in the string. We have to make it a function. So do I two functions-one to analyze the string and then one to count, or I can do it all in one? Here is my recent code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    int vowelcount(char *text);
    int digitcount(char *text);
    
    void main(void) {
    	
    	int x, y, d, size;
    	char text[81];
    
    	printf("Please type a string or hit 'Enter' to quit:\n");
    	fgets(text, 81, stdin);
    
    	while (text[1]!='\0') {
    		size=strlen(text)-1;
    		printf("count=%d\n", size);
    		d=digitcount(text);
    		printf("digit=%d\n", d);
    		y=vowelcount(text);
    		printf("vowel=%d\n", y);
    
    
    
    
    
    		printf("Please type a string or hit 'Enter' to quit:\n");
    		fgets(text, 81, stdin);
    	}
    }
    
    int vowelcount(char *text) {
    	
    	int x, y;
    
    	y=0;
    	toupper(text[x]);
    
    	for(x=0; text[x]!='\0'; x++)
    		if(text[x] == 'A' || text[x] == 'E' || text[x] == 'I' || text[x] == 'O' || text[x] == 'U')
    			y++;
    	
    	return y;
    }
    
    int digitcount(char *text) {
    	
    	int x, d;
    	
    	d=0;
    	
    	for(x=0; text[x]!='\0'; x++)
    		if(isdigit(text[x]))
    			d++;
    	
    	return d;
    }

  15. #15
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Code:
    int vowelcount(char *text) {
    	
    	int x, y;
    
    	y=0;
    	toupper(text[x]);    // Look more into the placement and usage of this
    
    	for(x=0; text[x]!='\0'; x++)
    		if(text[x] == 'A' || text[x] == 'E' || text[x] == 'I' || text[x] == 'O' || text[x] == 'U')
    			y++;
    	
    	return y;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM