Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int lexCompare(char* a, char* b){
- int i;
- int r = strlen(a);
- int q = strlen(b);
- // ret 1 for a is small &&& ret -1 for b is small
- for(i=0;(i<r||i<q);i++){
- if(a[i] == '\0') return 1;
- else if(b[i] == '\0') return -1;
- else if(a[i] < b[i]){
- return 1;
- }
- else if(a[i] > b[i]){
- return -1;
- }
- }
- return 0;
- }
- int main() {
- char str1[] = "Zeo", str2[] = "Zed";
- printf("The result is : %d",
- lexCompare(str1,str2)
- );
- return 0;
- }
Add Comment
Please, Sign In to add comment