hey all, hope you had a fine weekend does someone mind explaining which parameter is which in this. i know it compares two strings, but i can't tell which does what? thanks
Code:if(strcmp(n[index],n[index+1])>0)
hey all, hope you had a fine weekend does someone mind explaining which parameter is which in this. i know it compares two strings, but i can't tell which does what? thanks
Code:if(strcmp(n[index],n[index+1])>0)
It looks like this is an array of char *, strcmp tests one string in the array with the next string in the array. n[index] is the first argument, n[index+1] is the second.
-Prelude
My best code is written with the delete key.
I believe strcmp returns 0 if the 2 strings are of equal value. And I suppose those would be arrays of char*, because strcmp doesn't accept chars as parameters...
sorry should have posted more. what's the >0 at the end. is this the right track: if index+1 is greater than index than . . .
Code:for(index=0;index<max-1;index++) { if(strcmp(n[index],n[index+1])>0) { strcpy(temp,n[index]); strcpy(n[index],n[index+1]); strcpy(n[index+1],temp); swapflag=1; }
If strcmp returns 0 then the strings are equal, if it returns greater or less than 0 then the strings aren't equal.
-Prelude
My best code is written with the delete key.
strcmp(a, b) > 0 if a > b
strcmp(a, b) == 0 if a == b
strcmp(a, b) < 0 if a < b
AFAIK anyway.