lisedaton 0 Newbie Poster

H ALL!!

IT CAN BE SAID IM DONE WITH THIS PROGRAM THAT ITS MAKING ME CRAZY... BUT IM HAVING A PROBLEM... (I PAINT THEM RED AND WROTE THE PROBLEM BESIDE IT...)

PLEASE PLEASE
HELP!!!!!!!!!!!!!!!!!!!!!!

THE PROGRAM IS SUPOSSE TO RECIEVE A SENTENCE AND THEN SPLIT IT TO WORDS AND COMPARE THE WORDS AND IF THEY ARE "EQUAL " PRINT THEM!!:..... CANT USE FUNCTIN LIKE STRTROK....

EQUAL DEFINITION:
1--- DOESNT MATTER HOW MANY TIMES A LETTER APPEARS IN THE WORD...
2-- DOESNT MATTER IF THEY ARE WRITTEN IN UPPERCASE OR LOWER CASE...

EXAMPLE...... NANNY , ANY

THANK YOU ALL IN ADVANCED!

#include <stdio.h>
#include <string.h>

char wordA(char sentence[80], int x);
char wordB(char sentence[80], int x);
int endwordA(char sentence[80], int x);
int endwordB(char sentence[80], int x);
void checkword(char word1[80], char word2[80]);

int main()
{
char sentence[80], word1[80], word2[80];
int x=0, endword1=0, endword2=0, counter1, counter2, endwordimp;

printf("Please enter a sentence\n");
gets(sentence);

//running the sentence
while (sentence[x]!='\0')
{
	int i=0;
	int w=1;
		//separating the first word.....
		strcpy(word1, wordA(sentence,x)); /// THIS IS AN ERROR.... BUT I HAVE NO IDEA HOW TO ARRANGE IT... IM SUPOSSE TO SAFE THE VALUE THAT RETURNS FROM THE FUNCTION (CHAR) IN WORD1......
		endword1= endwordA(sentence, x);
		endwordimp = endword1;
		while (i!=w)
		{
			// searching for the second word....
			strcpy(word2, wordA(sentence, endword1)); /// THIS IS AN ERROR.... BUT I HAVE NO IDEA HOW TO ARRANGE IT... IM SUPOSSE TO SAFE THE VALUE THAT RETURNS FROM THE FUNCTION (CHAR) IN WORD1......
			endword2= endwordB(sentence, endword1);

			//cheking the letters of each word.... and printing them if they are the same...
			checkword(word1, word2);
			// after comparing them... the sentences need to check the next word...
			endword1= endword2;
				if (sentence[endword2]=='\0' || sentence[endword2+1]=='\0')
				{
					i=w;
					sentence[x]= sentence[endwordimp];
				}
				else 
				{
				endword1= endword2;
				}
		}
	}
system("PAUSE");
return 0;
}


// FUNCTION THAT CHECKS THE WORDS
void checkword(char word1[80], char word2[80])
{
	int y=0, x=0, letter_counter1[26]={0}, letter_counter2[26]={0};
	// cheking the letters in the first word
	for (x=0; x<=strlen(word1); x++)
	{
		if ((letter_counter1[word1[x]-65]) || (letter_counter1[word1[x]-97])==0)
		{	
			letter_counter1[word1[x]-65]++;
		}
	}
	// cheking the letters in the second word....
	for (x=0; x<=strlen(word2); x++)
	{
		if ((letter_counter2[word1[x]-65]) || (letter_counter2[word1[x]-97])==0)
		{	
			letter_counter2[word1[x]-65]++;
		}
	}
	// comparing them...
	for (y=0; y<26; y++)
	{
		if (letter_counter1[y]== letter_counter2[y])
		{
			continue;
		}
		else
		{
			break;
		}
	}
	// if they are the same, print them... else... finish the function!...
	if (y=26)
	{
		printf ("%s %s", word1, word2);
	}
return;
}

///// FUNCTION THAT CREATE ME THE FIRST WORD
char wordA(char sentence[80], int x)
{
	char  word1[80];
    int y=0, w=0;
	// to get to the first letter of the word...
	while ((sentence[x]>122 || sentence[x]<97) && (sentence[x]>90 || sentence[x]<65))
			{
               x++;
			}
	// to know the lenght of the word
	for (y=0; y<= strlen(sentence); y++)
	{
		if ((sentence[y]>=97 && sentence[y]<=122) || (sentence[y]>=65 && sentence[y]<=90))
		{
			w=y;
            }
		else
			break;
	}
	// saving the word separately....
	for (x; x<=w; x++)
	{
		strcpy(word1[x],sentence[x]);// PROBLEM  HERE IM TRYING TO SAVE THE FIRST WORD OF A SENTENCE IN A NEW CHAR 
	}
return (word1);// PROBLEM HERE.... ITS NOT LETTING ME RETURNING THE WORD!!!!!!
}

/////////////////// functions that takes me to the end of the first word!
int endwordA(char sentence[80], int x)
{
	int y=0, w=0;
	while ((sentence[x]>122 || sentence[x]<97) && (sentence[x]>90 || sentence[x]<65))
			{
               x++;
			}
			y=x;
	// to know the lenght of the word
	for (y; y<= strlen(sentence); y++)
	{
		if ((sentence[y]>=97 && sentence[y]<=122) || (sentence[y]>=65 && sentence[y]<=90))
		{
			w=y;
		}
		else
			break;
	}
return (w);
}

/// FUNCTINOS THAT GIVES ME THE SECOND WORD... (WORD TO COMPARE)
char wordB(char sentence[80], int endword1)
{
	int y=0, w=0;
	char word2[80];
	int x= endword1;
	// to get to the first letter of the word...
	while ((sentence[x]>122 || sentence[x]<97) && (sentence[x]>90 || sentence[x]<65))
			{
               x++;
			}
			y=x;
	// to know the lenght of the word
	for (y=0; y<= strlen(sentence); y++)
	{
		if ((sentence[y]>=97 && sentence[y]<=122) || (sentence[y]>=65 && sentence[y]<=90))
		{
			w=y;
            }
		else
			break;
	}
	// saving the word separately....
	for (x; x<=w; x++)
	{
		strcpy(word2[x],sentence[x]);
	}
return (word2);
}

/////// FUNCTION THAT TAKES ME TO THE END OF THE SECOND WORD.......
int endwordB(char sentence[80], int endword1)
{
    int y=0, w=0, x=endword1;
	while ((sentence[x]>122 || sentence[x]<97) && (sentence[x]>90 || sentence[x]<65))
			{
               x++;
			}
			y=x;
	// to know the lenght of the word
	for (y; y<= strlen(sentence); y++)
	{
		if ((sentence[y]>=97 && sentence[y]<=122) || (sentence[y]>=65 && sentence[y]<=90))
		{
			w=y;
		}
		else
			break;
	}
return (w);
}