English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

6 answers

I will write steps to solve this problem. And I think, you will be able to solve this problem.

1) Get two strings (Input from user or any other source)
2) Compare the length of both strings. If length is not same, the strings are obviously different.
3) If above condition fails (means, the length of strings are same), write a loop (either for/while/do-while) and compare each character. Like 1st character of 1st string should be equal to 1st character of 2nd string and so on. If any of character is not matched, the strings are not the same.

We can use strcmp or similar function to do this. But your assignment is to not use this kind of functions, so u have to compare it in the way, i have described.

2007-03-19 02:32:04 · answer #1 · answered by Atif Majid 3 · 0 0

All the above answers are correct. I would like to add that if you are not using strings, declare the variable as an array of characters. For example, char[20]....etc. Then, you can compare the two strings, character by character, using just one loop!
Hope this helps!
Good Luck!

2007-03-19 04:04:44 · answer #2 · answered by A.Samad Shaikh 2 · 0 0

What does it advise to get the ASCII equivalent? Characters are saved(on maximum implementations) as ASCII (or utf-8, of which ASCII is a subset), so there is no longer something to 'get', it really is already there. you are able to research characters promptly, in a for loop. be particular to purpose for the null terminator('0' or in simple terms 0) to entice close even as the string is ended.

2016-11-26 22:12:07 · answer #3 · answered by ? 4 · 0 0

Well, without using string class just compare them as ordinary arrays.. First the size (if it doesn't match then they can't be the same) and afterwards character by haracter...

2007-03-19 02:31:12 · answer #4 · answered by agent-X 6 · 0 0

char string1[256];
char string2[256];

cin.getline(string1, 256);
cin.getline(string2, 256);

if(strcmp(string1, string2) == 0){
cout << "Strings are equal";
}
else{
cout << "Strings are not equal";
}

2007-03-19 08:57:45 · answer #5 · answered by rsmith985 3 · 0 0

You can easily understand my code here (or already...).

bool CheckTwoStrings(char* str1,char* str2)
{

if(strlen(str1)!=strlen(str2)) return false;
/* If you don't want to use strlen, then here my strlen function below */

while(*str1!='\0')
{
if ((*str1)!=(*str2)) return false;
str1++;
str2++;
}

return true;

}

int strlen(char *p)
{
int i=0;
while(*p!=0)
{
i++;
p++;
}
return i;
}

then, i think it's almost up...
If you got anything not clear or better suggestion, then please call me... cruisernk@yahoo.com

2007-03-19 04:00:46 · answer #6 · answered by QuizBox 2 · 0 0

fedest.com, questions and answers