/** * Program to illustrate simple function on strings. */ #include #include /* print str, a character at a time, using array notation */ void my_print1(char str[]) { int i = 0; while (str[i] != '\0') { printf("%c (%d)\n", str[i], (int) str[i]); ++i; } printf("null character is %d\n\n", (int) str[i]); } /* print str, a character at a time, using a pointer */ void my_print2(char *str) { char * p = &str[0]; while (*p != '\0') { printf("%c (%d)\n", *p, (int) *p); ++p; } printf("null character is %d\n\n", (int) *p); } /* main program */ int main(void) { char my_string[10] = "hello"; printf("output using my_print1:\n\n"); my_print1(my_string); my_print1("bye bye"); printf("output using my_print2:\n\n"); my_print2(my_string); my_print2("bye bye"); return EXIT_SUCCESS; }