Question:
C program: Pig Latin translator, can someone help with these last 3 errors?
2010-11-18 02:45:45 UTC
The errors are listed at the bottom


#include
#include


void translate_sentence (char *c)
{
char sentence[81];
char *psentence;
while (strchr("aeiouAEIOU",*c) == NULL) /*this checks for a vowel at the beginning of the words*/
{
char consonant = *c;
char to = *c, *from=c+1;

while (*from *to++ == *from++)
{
consonant = *to; /**Error 1 is this line**/
}
}
printf("%say", *c);

}





void main (void)
{
char sentence[81];
char *psentence;

/*Instructions to the user*/
printf("This program translates your sentence into pig latin.");
printf("Please type in a sentence or type stop: ");


gets (sentence);
printf("You typed in \n%s \n");
word = strtok(sentence, " "); /**Error 2 and Error 3 in this line**/
translate_sentence(word);
printf("\n");


}

error1: error C2100: illegal indirection
error2: error C2065: 'word' : undeclared identifier
error3: error C2440: '=' : cannot convert from 'char *' to 'int'
Three answers:
cja
2010-11-18 05:29:18 UTC
See below for some changes I made to get your program compiling and running. It now does something, but it's not correct, i.e. it doesn't translate a sentence into pig latin.



E.g., if I type in: I am speaking Pig Latin

your program outputs: Iay

when it should display: Iway amway eakingspay igPay atinLay



Also, your prompt implies that entering "stop" will end the program, but you have no logic for this.



#include

#include



#define MAX_LINE_LEN 81



void translate_sentence (char *c) {

    while (strchr("aeiouAEIOU",*c) == NULL) {

        char consonant = *c;

        char *to = c, *from=c+1;

        while (*to++ == *from++) {

            consonant = *to;

        }

    }

    printf("%say", c);

}



int main (int argc, char *argv[]) {

    char sentence[MAX_LINE_LEN];

    char *word;



    puts("This program translates your sentence into pig latin.");

    printf("Please type in a sentence or type stop: ");



    fgets(sentence,MAX_LINE_LEN,stdin);

    *(strchr(sentence, '\n')) = '\0';

    printf("You typed in \n%s \n", sentence);

    word = strtok(sentence, " ");

    translate_sentence(word);

    printf("\n");



    return 0;

}
Neochi
2010-11-18 02:57:38 UTC
error 2 is because you are using word but you did not declare what type it is.. see how you have :

char sentence[81]; you declared a variable cllaed sentence of type char and gave it a size.



Well, you did not do the same for word. So first declare word as a char or string before you use it.



in otherwords



if you use the following



y= 5;



instead of

int y;

y=5;



you get "y" undelcared identifier.



so in this case, you did :

word

but no char word[81]; or anything like it



in summary for error 2: declare what your variable called word is.



I think you meant to call it psentence? cause it doesn't look like you used psentence anywhere...



you are on your own with the rest :(
magee
2016-12-05 10:19:34 UTC
I controlled to get it working...what I did grew to become into I further a clean variable (called avg1) and gave your function a return fee (if a function isn't void it desires to return something), and renamed all references to avg to avg1. the reason you have been getting that errors grew to become into by way of fact (the workstation thinks) you have been tiring to preform an combination (an operation that addresses the function as one merchandise) operation, which isn't allowed in C++ till you perform a little form of overloading, regardless please take a seem at my answer and study from it. ultimate of luck in the programming international, its quite relaxing!!! #contain iostream #contain utilising namespace std; double avg (double a, double b, double c,double avg1); int important () { double a, b, c,avg1; avg(a,b,c,avg1); cout<<"enter a quantity it is bigger than 0:"; cin>>a; cout<<"enter yet another quantity better than 0:"; cin>>b; cout<<"enter the outstanding quantity:"; cin>>c; cout<<"the common of the three numbers is:"; cout<> z; return 0; } double avg (double a, double b, double c,double avg1) { avg1=(a+b+c)/3; return 0; }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...