Error in strcmp

I am getting error while using strcmp(s1,s2)
Here is the code :-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream.h>
#include<string.h>
#include<conio.h>

void main()

{
clrscr();
char s1,s2;
cin>>s1>>s2;
if(strcmp(s1,s2)!=0)
{
cout<<"Correct";
}
else
{
cout<<"Wrong";
}
getch();
}

The Errors I get are :-

1)Cannot convert 'int' to 'const char *'
2)Type mismatch in parameter '_s1' in call to 'strcmp(const char *, const char *)'
3)Type mismatch in parameter '_s2' in call to 'strcmp(const char *, const char *)'

Please help me.


>>>>>THE PROGRAM IS TO BE MADE ON TURBO C++<<<<<
All the help provided will be appreciated
Last edited on
Line 9:
 
    char s1,s2;

s1 and s2 are just a single character each, they can hold one character such as 'A' or '2'.

To compare s1 and s2 then you would need simply,
1
2
3
4
    if (s1 == s2)
        cout << "same";
    else
        cout << "different";



However, what you really want to know is how to use strcmp to compare two strings. A string here is an array of characters. You define such an array by specifying the size - how many characters it will be able to hold.

Hence line 9 might look like this:
1
2
    char s1[50];   // room for 49 characters
    char s2[50];   // last character is reserved for null terminator. 


See tutorial:
http://www.cplusplus.com/doc/tutorial/ntcs/

and also reference page
http://www.cplusplus.com/reference/cstring/strcmp/

Topic archived. No new replies allowed.