0

i tried to make a program to compare two string and display which character will come first as you can see below but it gives certain error can any one guide me what changes i have to make

int Mystrcmp (const char* , const char* );
{

cout<<Mystrcmp(v1,v2);
}
int Mystrcmp (const char* v1, const char* v2 )
{
char value1[10]="new york";
    char value2[9]="st louis";
    char result;
    v1=&value1[0];
    v2=&value2[0];
    if (strcmp (value1, value2) < 0)
    result=cout<<value1<<value2;
    return result;
    else
    result=cout<<value2<<value1;
    return result;

Edited by WaltP: Added CODE Tags yet again!!!!

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by WaltP
0
char value1[10]="new york";
char value2[9]="st louis";
char result;
v1=&value1[0];
v2=&value2[0];

All those lines are in the wrong function. Mystrcmp() needs to compare the two strings that are the parameters to the function.

int main()
{
   char value1[]="new york";
   char value2[]="st louis";
   int x = Mystrcmp( value1, value2 );
}
0

We've added CODE Tags for the last time for you. You already have 4 infractions and 1 warning for not using them. 1 more infraction and you will be banned. This constitutes your last warning.

Follow the rules.

Edited by WaltP: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.