ok, the assignment was also supposed to be able to put the original word backwards, and so i tried (at the bottom) to do so, and it only prints the first letter. Why? and how to fix it?
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char word[31];
char pig[40] = "";
int len;
char two[3] = "";
char one[2] = "";
int i;
printf("Input the word you want to put into pig latin and backwards (MAX: 30 characters) \n");
scanf("%s", word);
len = strlen(word);
for(i = 0; i < len; i ++) {
word[i] = toupper(word[i]);
}
strncpy(two, word, 2);
two[2] = '\0';
strncat(one, word, 1);
if (strcmp(two, "WH") == 0 || strcmp(two, "CH") == 0) {
strcpy(pig, &word[2]);
strcat(pig, two);
strcat(pig, "AY");
}
else if (strcmp(two, "SH") == 0 || strcmp(two, "TH") == 0){
strcpy(pig, &word[2]);
strcat(pig, two);
strcat(pig, "AY");
}
else if (strcmp(two, "PH") == 0 || strcmp(two, "QU") == 0) {
strcpy(pig, &word[2]);
strcat(pig, two);
strcat(pig, "AY");
}
else if (word[0] == 'A' || word[0] == 'I') {
strcpy(pig, word);
strcat(pig, "AY");
}
else if (word[0] == 'E' || word[0] == 'O') {
strcpy(pig, word);
strcat(pig, "AY");
}
else if (word[0] == 'U') {
strcpy(pig, word);
strcat(pig, "AY");
}
else {
strcpy(pig, &word[1]);
strcat(pig, one);
strcat(pig, "AY");
}
printf("This is the pig latin: %s \n", pig);
char backword[31];
int n = 0;
while(n < len) {
strcpy(backword, &word[n]);
n += 1;
}
printf("This is the word backwards: %s \n", backword);
return 0;
}