PigLatin

Working on this program and I am kind of stuck

When I try to show the call the rule1 function to show the swap nothing changes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void UserWord ( char [] );
void RuleOne ( char [] );

void main()
{
	char word[10];

	printf( "This program will HOPEFULLY translate a word from English to Pig Latin.\n\n" );

	UserWord( word );

	RuleOne( word);

	system( "pause" );
}

void UserWord ( char x[] )
{
	printf( "Please enter a word: " );
	scanf( "%s", x );
	printf( "\n" );
	printf( "The word you entered is: %s\n\n", x );
	printf( "The length of your word is: %d\n\n", strlen( x ) );
}

void RuleOne ( char x[] )
{
	if ( x[ 0 ] == 'a' || x[ 0 ] == 'e' || x[ 0 ] == 'i' || x[ 0 ] == 'o' || x[ 0 ] == 'u' ||
		x[ 0 ] == 'A' || x[ 0 ] == 'E' || x[ 0 ] == 'I' || x[ 0 ] == 'O' || x[ 0 ] == 'U') {
		strcat( x, "way" );
	}

	printf( "The word you entered is: %s\n\n", x );
	printf( "The length of your word is: %d\n\n", strlen( x ) );
}

First of all, stop using "void main()", main is an integer returning function, neglecting the return type can lead to bad things like stack corruption after your program exits. It's on the creator of C++'s website. "void main()" has never been valid in C or C++.

http://www2.research.att.com/~bs/bs_faq2.html#void-main


Secondly, I think you may under-allocating with only 10 characters, about 1024 or 2048 MAY be sufficient.


Also, the functions in <ctype.h> can be very useful for converting toupper and tolower.
ex:
if(toupper(x[0]) == 'A')
But first you may want to verify the character is actually a letter with isalpha() also in that header file.
Topic archived. No new replies allowed.