Reputation: 23
I am trying to do coping string to string but
Compiler gives Cannot convert Char to Char For 19,20 Lines; Couldn't find what is wrong with this?
int main ()
{
int i=0;
int j=0;
int space = 0;
char cmp[50];
char *p[50][100];
for (i=0;i<space;i++) {
for ( j = i + 1;j <=space; j++ ) {
if( (strcmp(p[i],p[j])=0)) //15 {
strcpy (cmp,p[i]); //18
strcpy (p[i],p[j] ); //19
strcpy(p[j], cmp); //20
}
}
}
}
Upvotes: 1
Views: 1453
Reputation: 740
Try this code, but let me tell you this code swaps same strings if value of space is some positive number.
int main ()
{
int i=0;
int j=0;
int space = 0; //I hope you initialized the value of space to a different number.
char cmp[50];
char p[50][100];// do not use *p[50][100]
for (i=0;i<space;i++) {
for ( j = i + 1;j <=space; j++ ) {
if( (strcmp(p[i],p[j])==0)) { //use == for comparison.
strcpy (cmp,p[i]);
strcpy (p[i],p[j] );
strcpy(p[j], cmp);
}
}
}
}
Upvotes: 3
Reputation: 64682
So many problems.....
for (i=0;i<space;i++) {
What do you think the value of space
is?
if space
is zero, how many times do you think this loop will run?
How many times do you want it to run?
Upvotes: 1