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;

Recommended Answers

All 2 Replies

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 );
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.