-
Well you're mixing up the {} - adding them where they're not needed, and removing them where they are.
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int EWord(char *str);
void LWord(char *str);
int isVowel( char ch ) {
int res = 0;
ch = tolower( ch );
if(ch == 'a' ||
ch == 'e' ||
ch == 'i' ||
ch == 'o' ||
ch == 'u') res = 1;
return res;
}
int beginsConsonant( char word[] ) {
return !isVowel( word[0] );
}
int main(void) {
char Word[100];
printf( "Welcome to the Pig Latin Translator!\n\n" );
printf( "Please enter your word(s):\n\n" );
while(scanf( "%s", Word ) == 1) {
if(stricmp( Word, "stop" ) == 0) return 0;
if(EWord( Word )) LWord( Word );
}
return 0;
}
int allConsonant( char word[] ) {
int len = strlen( word );
int i, res = 1;
for(i = 0 ; i < len ; i++) {
if(isVowel( word[i] )) res = 0;
} //!! ADDED
return res;
}
void pigLatin( char word[] ) {
if(beginsConsonant( word ) && !allConsonant( word )) {
printf( "%s%cay ", &word[1], word[0] );
} else {
printf( "%sway ", word );
}
//!! REMOVED }
}
Does your editor preserve this indentation?
There are many free code editors around which understand program indentation, and know how to match up {} so you can see whether they are balanced or not
Which OS / Compiler are you using
-
Error: Expression Syntax in function allConstant
for what i can see
Code:
int allConsonant ( char word[] ) {
int len = strlen( word );
int i, res = 1;
for ( i = 0 ; i < len ; i++ ) {
if ( isVowel(word[i]) ) res = 0;
<--------- (missing for loop brace)
return res;
}
e.g
Code:
int allConsonant ( char word[] ) {
int len = strlen( word );
int i, res = 1;
for ( i = 0 ; i < len ; i++ ) {
if ( isVowel(word[i]) ) res = 0;
} <-------- brace in place
return res;
}
-
Ok Guys I did what you two said and it got rid of the errors that I got before, But now I have 2 different errors. My current code is below and the errors will be after it. Im stilll messing with stuff to see whats wrong, but I want to keep you guys updated.
Salem, what are you asking me with the first question (Does your editor preserve this indentation?) ?? And the compiler I am using is called Turbo C.
Heres my current code:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int EWord(char *str);
void LWord(char *str);
int isVowel ( char ch ) {
int res = 0;
ch = tolower( ch );
if ( ch == 'a' ||
ch == 'e' ||
ch == 'i' ||
ch == 'o' ||
ch == 'u' ) res = 1;
return res;
}
int beginsConsonant ( char word[] ) {
return !isVowel( word[0] );
}
int main(void)
{
char Word[100];
printf("Welcome to the Pig Latin Translator!\n\n");
printf("Please enter your word(s):\n\n");
while(scanf("%s", Word) == 1)
{
if( stricmp( Word, "stop" ) == 0 ) return 0;
if(EWord(Word)) LWord(Word);
}
return 0;
}
int allConsonant ( char word[] ) {
int len = strlen( word );
int i, res = 1;
for ( i = 0 ; i < len ; i++ ) {
if ( isVowel(word[i]) ) res = 0;
}
return res;
}
void pigLatin ( char word[] ) {
if ( beginsConsonant(word) && !allConsonant(word) ) {
printf( "%s%cay ", &word[1], word[0] );
} else {
printf( "%sway ", word );
}
}
The two errors are:
Linker Error: Undefined symbol '_LWord' in module PIGLAT10.TXT
Linker Error: Undefined symbol '_EWord' in module PIGLAT10.TXT
*Also there is NOTHING highlighted in the program to show the errors. So I dont know whats wrong.
-
Looks like I spoke too soon.
Ok I changed some things and my new current code is below. Now the changes I made made the code able to run. So it runs perfectly. BUT and this is a big but. Though it runs, it does NOT translate any words at all. NONE, it runs but just stays there waiting for words, I type them in, it doesnt translate and it just puts a cursor for the next word to be typed in. The ONLY word it recognizes is "Stop" and it will end the running program just like I want it too. But it just doesnt translate. Now Im really stuck. Im guessing everything is correct, I just have to put things in different orders. Lets see what you guys can figure out. Thanks for your help
My code:
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int EWord(char *str);
void LWord(char *str);
int isVowel ( char ch ) {
int res = 0;
ch = tolower( ch );
if ( ch == 'a' ||
ch == 'e' ||
ch == 'i' ||
ch == 'o' ||
ch == 'u' ) res = 1;
return res;
}
int beginsConsonant ( char word[] ) {
return !isVowel( word[0] );
}
int main(void)
{
char Word[100];
printf("Welcome to the Pig Latin Translator!\n\n");
printf("Please enter your word(s):\n\n");
while(scanf("%s", Word) == 1)
{
if( stricmp( Word, "stop" ) == 0 ) return 0;
if(EWord(Word)) LWord(Word);
}
return 0;
}
int EWord ( char word[] ) {
int len = strlen( word );
int i, res = 1;
for ( i = 0 ; i < len ; i++ ) {
if ( isVowel(word[i]) ) res = 0;
}
return res;
}
void LWord ( char word[] ) {
if ( beginsConsonant(word) && !EWord(word) ) {
printf( "%s%cay ", &word[1], word[0] );
} else {
printf( "%sway ", word );
}
}
-
Your current EWord
Code:
int EWord ( char word[] ) {
int len = strlen( word );
int i, res = 1;
for ( i = 0 ; i < len ; i++ ) {
if ( isVowel(word[i]) ) res = 0;
}
return res;
}
Your original EWord
Code:
int EWord(char *str)
{
int Cnt = 1;
while(*str)
if(!isalpha(*str++)) Cnt = 0;
return !!Cnt;
}
If you type in a word with no vowels at present, it does work, its just that your EWord function calls isVowel rather than isascii.