| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Syntax errors - Error C2568 'indentifier': unable to resolve function overload
I am having a hard time understanding how to pass arguments to a function. I have errors on all of my function call arguments. It seems like it should be fairly straight forward but it's not. Here is my program. I am basically trying to pass a userstring and list of vowels, then count vowels, consonants or both. I apprecaite any suggestions.
//Function prototypes int countVowels(char *, char[]); int countConsonant(char *, char[]); int countCharacters(char *, char[]); char input[]; char *strPtr; int main() { char choice; int length; length = strlen(input); char vowels[] = {'a'||'A', 'e'||'E', 'i'||'I', 'o'||'O', 'u'||'U'}; //*********************************************** // Get string from user. * //*********************************************** cout << "Enter a string. "; cin.getline(input, length); //************************************************** //Display menu. * //************************************************** do { cout << "A) Count the number of vowels in string \n"; cout << "B) Count the number of consonants in string \n"; cout << "C) Count both vowels and consonants in string \n"; cout << "D) Enter another string \n"; cout << "E) Exit the program \n"; cin >> choice; //************************************************** //Respond to user's choice. * //************************************************** switch (choice) { case 'A': case 'a': cout << "Your string has " << countVowels (input, vowels) << " vowels."; endl; break; case 'B': case 'b': cout << "Your string has " << countConsonant (input, vowels) << " consonants."; endl; break; case 'C': case 'c': cout << "Your string has " << countCharacters (input, vowels) << " characters."; endl; break; } } while (choice != 'E'||'e'); return 0; } //************************************************** ** // Count vowels. * //************************************************** ** int countVowels(char *strPtr, char vowels) { int vowCount = 0; // Vowel total while (*strPtr != '\0') { if (*strPtr == vowels) vowCount++; strPtr++; } return vowCount; } //************************************************** ** // Count Consonants. * //************************************************** ** int countConsonant(char *strPtr, char vowels) { int conCount = 0; // Consonant total while (*strPtr != '\0') { if (*strPtr != vowels) conCount++; strPtr++; } return conCount; } //************************************************** * // Count Characters * //************************************************** * int countCharacters (char *strPtr, char vowels) { int charCount = 0; // Character total while (*strPtr != '\0') { charCount++; strPtr++; } return charCount; } |
|
#2
|
|||
|
|||
|
you can not have call a function in the argument of a function...
|
|
#3
|
|||
|
|||
|
larssss:
Your reply is bull**** no matter which way I read it. llschrad: Your program has plenty problems in it. The first and most obvious would be easily solved by using the standard library string instead of a mishmash of char* and char[]. char input[]; // How long? Might turn this into a char* pointing to anywhere. int length = strlen(input); // The length of... what? Does not do what you expect in either case. The reason you get that particular error message may be related to that int countVowels(char *strPtr, char vowels) definition below which takes another set of parameters, and the compiler does not know which one to pick. Note that your way of finding these vowels in the string fails... char vowels[] = {'a'||'A', 'e'||'E', 'i'||'I', 'o'||'O', 'u'||'U'}; 'a'||'A' resolves to the boolean value true, which when converted to an 8bit int (that is, char) is typically 1. (May vary with compiler) In other words, you're really writing char vowels[] = {1,1,1,1,1}; Use const char* vowels = "aAeEiIoOuU" instead. And when you do the comparison to a single char in the defined function... you'd only be checking for that particular one anyway. If you really really cannot use std::string, do this: const int maxlen = 64; // Must have a value... char input[maxlen]; and use that maxlen rather than your erronous length measurement. Also, use all char* in your function parameters, unless you have a number in them. When you pass a char[] to anywhere requiring a char* you might want to use &name[0] if the compiler complains.
__________________
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Syntax errors - Error C2568 'indentifier': unable to resolve function overload |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|