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?
Printable View
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?
isvowel() is not part of the C standard. You would have to write your own routine.
Here's one:
That's the way I'd do it anyway :) Unless 'Y' also counts...Code:int isvowel(int ch)
{
int c = toupper(ch);
return (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
Ok what I'm trying to do is count the number of vowels in a string. This is what I have so far:
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?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;
}
Been a while since I been here...
how this for a start..
I know it removes blanks but can you see some possiblities..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 hope you do...like reading in a string, checking the string, etc...
:)
I understand some of your program, but what is *t++ = *s;?
It has the effect of setting *t equal to *s and then incrementing t.
Please, God, no.Quote:
Originally Posted by Mister C
Most worrisome is your title when I see this.
[edit]Given t's initialization, this is dereferencing a NULL pointer, which is most certainly undefined behavior.Code:*t++ = *s;
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;
}
}
But that is C++, not C.
Itsme86's solution is a nice one, though.
It's all there. You're sending a string (char*) to a function that receives a single char. It should beQuote:
Originally Posted by nizbit
Second you have a infinite loop...Code:y=vowelcount(text[index]);
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.
> 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.
I believe we had fun covering isvowel here a while back.
Quzah.
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;
}
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;
}