hi everybody!...
so i have this assigment for monday and im having trouble with it... the program in c should get:
input:
a sentence.....nanny do you have any cheap peach...
and it should print the "same" words...:
nanny any
cheap peach
..they are called "same words when they get the same letter no matter upper or lower case and how many time each letter....
so this is my code i have no idea whats wrong... but can somebody help me fixe it????
thank you alll!
#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);
int checkword(char word1[80]);
int main()
{
char sentence[80], word1[80], word2[80];
int x=0, endword1=0, endword2=0, counter1, counter2, endwordimp;
// receives the input from the user
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.....
word1[x]= wordA(sentence, x);
endword1= endwordA(sentence, x);
endwordimp = endword1;
while (i!=w)
{
// searching for the second word....
word2[x]= wordB(sentence, endword1);
endword2= endwordB(sentence, endword1);
//cheking the letters of each word....//....returns the real value of each letter in the word!...
counter1= checkword(word1);
counter2= checkword(word2);
// comparing the words...
if (counter1==counter2)
{
printf ("%s %s", word1, word2);
endword1= endword2;
if (sentence[endword2]=='\0' || sentence[endword2+1]=='\0')
{
i=w;
sentence[x]= sentence[endwordimp];
}
}
else
{
endword1= endword2;
if (sentence[endword2]=='\0' || sentence[endword2+1]=='\0')
{
i=w;
sentence[x]= sentence[endwordimp];
}
}
}
}
system("PAUSE");
return 0;
}
// FUNCTION THAT CHECKS THE WORDS
int checkword(char word1[80])
{
int counter=0, x=0;
for (x; word1!='\0'; x++)
{
if ((word1[x]>=65) && (word1[x]<=90))
{
counter= (int)word1[x];
}
else
{
counter= (int)word1[x] - 32;
}
}
return (counter);
}
///// FUNCTION THAT CREATE ME THE FIRST WORD
char wordA(char sentence[80], int x)
{
char word1[80];
int y=0;
for (x; x<=strlen(sentence) ; x++)
{
while ((sentence[x]>122 || sentence[x]<97) && (sentence[x]>90 || sentence[x]<65))
{
x++;
}
for (x; x<=strlen(sentence); x++)
{
if ((sentence[x]>=97 && sentence[x]<=122) || (sentence[x]>=65 && sentence[x]<=90))
{
word1[y]=sentence[x];
y++;
}
else
{
word1[y]='\0';
x++;
break;
}
break;
}
break;
}
return (word1);
}
/////////////////// functions that takes me to the end of the first word!
int endwordA(char sentence[80], int x)
{
char word1[80];
int y=0;
for (x; x<=strlen(sentence) ; x++)
{
if ((sentence[x]>=97 && sentence[x]<=122) || (sentence[x]>=65 && sentence[x]<=90))
{
word1[y]=sentence[x];
y++;
}
else
{
word1[y]='\0';
x++;
break;
}
}
return (x);
}
/// FUNCTINOS THAT GIVES ME THE SECOND WORD... (WORD TO COMPARE)
char wordB(char sentence[80], int endword1)
{
int y=0;
char word2[80];
int x=endword1;
for (x; x<=strlen(sentence) ; x++)
{
while ((sentence[x]>122 || sentence[x]<97) && (sentence[x]>90 || sentence[x]<65))
{
x++;
}
for (x; x<=strlen(sentence); x++)
{
if ((sentence[x]>=97 && sentence[x]<=122) || (sentence[x]>=65 && sentence[x]<=90))
{
word2[y]=sentence[x];
y++;
}
else
{
word2[y]='\0';
x++;
break;
}
}
break;
}
return (word2[80]);
}
/////// FUNCTION THAT TAKES ME TO THE END OF THE SECOND WORD.......
int endwordB(char sentence[80], int endword1)
{
char word1[80];
int y=0;
int x=endword1;
for (x; x<=strlen(sentence) ; x++)
{
if ((sentence[x]>=97 && sentence[x]<=122) || (sentence[x]>=65 && sentence[x]<=90))
{
word1[y]=sentence[x];
y++;
}
else
{
word1[y]='\0';
x++;
break;
}
}
return (x);
}
thanx!