/* File: quicker.c Quicker ways to access the characters in a string. */ #include #include "genlib.h" #include "simpio.h" #include "strlib.h" main() { string str ; char c ; int i, length ; str = "this line is all in upper case" ; /* This is a fast way */ printf("Method 1: ") ; for (i = 0 ; str[i] != '\0' ; i++) { c = str[i] ; c = toupper(c) ; printf("%c", c) ; } printf("\n\n") ; /* This is slower */ printf("Method 2: ") ; length = StringLength(str) ; for (i = 0 ; i < length ; i++) { c = IthChar(str,i) ; c = toupper(c) ; printf("%c", c) ; } printf("\n\n") ; /* This is the slowest */ printf("Method 3: ") ; for (i = 0 ; i < StringLength(str) ; i++) { c = IthChar(str,i) ; c = toupper(c) ; printf("%c", c) ; } printf("\n\n") ; }