| string-order.c - Et program der illustrerer den leksikografiske ordning af tekststrenge i C. | Lektion 7 - slide 14 : 26 Program 1 |
#include <stdio.h>
#include <string.h>
void pr(char*, char*, int);
int main(void) {
int b1 = strcmp("book", "shelf");
int b2 = strcmp("shelf", "book");
int b3 = strcmp("","book");
int b4 = strcmp("book","bookshelf");
int b5 = strcmp("book", "book");
int b6 = strcmp("7book", "book");
int b7 = strcmp("BOOK", "book");
pr("book", "shelf", b1);
pr("shelf", "book", b2);
pr("", "book", b3);
pr("book", "bookshelf", b4);
pr("book", "book", b5);
pr("7book","book", b6);
pr("BOOK", "book", b7);
return 0;
}
void pr(char *s, char *t, int r){
printf("strcmp(\"%s\",\"%s\") = %i\n", s,t,r);
}