/** * Two ways of doing strlen. The difference is just * using pointers or arrays. Both ways work. * Here is use "string" to mean an array of char that is * guaranteed to be null terminated * @author gtowell * Created: March 2021 * * **/ #include /** * The length of a string using pointers * @param a pointer to the beginning of a string. * @return the length of the string * **/ int strlenP(char *strPtr) { int i = 0; while (*strPtr != '\0') { strPtr++; i++; } return i; } /** * The length of a string using array notation * @param strArr the character array containing the string * @return the length of the string * **/ int strlenA(char strArr[]) { int i = 0; while (strArr[i] != '\0') { i++; } return i; } /** * Example using the command line parameters * **/ int main(int argc, char const *argv[]) { for (int i = 0; i < argc; i++) { printf("%d %d %s\n", strlenP(argv[i]), strlenA(argv[i]), argv[i]); } return 0; }