- #1
toforfiltum
- 341
- 4
< Mentor Note -- thread moved to HH from the technical Computer forum, so no HH Template is shown >
I have a homework problem which requires me to convert a word a user entered to Pig Latin by moving the first letter of the word to the end and adding an ay to it. For example, Tuesday becomes uesdayTay. This process should be repeated until the user types STOP.
I'm really new to arrays, so I might be using them wrongly, but I can't find out why. The program I wrote can be compiled but crashes whenever I execute it. I don't know if the logic behind my code is right either. I'm sure this program is rather simple, but here is my code:
I have a homework problem which requires me to convert a word a user entered to Pig Latin by moving the first letter of the word to the end and adding an ay to it. For example, Tuesday becomes uesdayTay. This process should be repeated until the user types STOP.
I'm really new to arrays, so I might be using them wrongly, but I can't find out why. The program I wrote can be compiled but crashes whenever I execute it. I don't know if the logic behind my code is right either. I'm sure this program is rather simple, but here is my code:
C:
#include <stdio.h>
#include <string.h>
int main ()
{
char *input_word [100] = {0} , *temp [100] = {0} , *stop [4] = {0};
int n = 0;
printf("Enter a word: ");
for( n = 0; n < 100; n++)
{
scanf("%s", input_word[n]);
} while ( strcmp ( stop [4], "STOP" ) != 0 )
{
*temp = input_word [0];
for ( int j = 1; j <= n-1; j++)
{
*input_word [j-1] = *input_word [j];
}
input_word [n-1] = *temp;
printf("%s", *input_word);
printf("ay\n");
printf("Type STOP to terminate: ");
for ( n = 0; n < 4; n++ )
{
scanf("%s", stop[n] );
}
}
return 0;}
Last edited by a moderator: