Script started on Mon Oct 6 17:28:56 2025 Restored session: Wed Oct 1 18:44:53 EDT 2025 macbook:logs> cd ../programs/C_ch9 macbook:C_ch9> echo attendance code 6275 attendance code 6275 macbook:C_ch9> grep power *.c power.c:int power(int x, int n) { power.c: printf("power(2,3) returns %d.\n", power(2,3)); power2.c:int power(int x, int n) { power2.c: printf("power(2,3) returns %d.\n", power(2,3)); macbook:C_ch9> cat power2.c /* Args vs Params See Dr. King's book, chapter 9 */ #include // Alternate form int power(int x, int n) { int result = 1; // n is a *copy* while (n-- > 0) result = result * x; return result; } int main (int argc, char *argv[]) { printf("power(2,3) returns %d.\n", power(2,3)); return 0; } macbook:C_ch9> gcc power2.c macbook:C_ch9> ./a.out power(2,3) returns 8. macbook:C_ch9> cp power2.c power2b.c macbook:C_ch9> vi power2b.c macbook:C_ch9> gcc power2b.c macbook:C_ch9> cat power2b.c /* Args vs Params See Dr. King's book, chapter 9 */ #include // Alternate form int power(int x, int n) { int result = 1; // n is a *copy* while (n-- > 0) result = result * x; return result; } int main (int argc, char *argv[]) { int a, b; a = 2; b = 3; printf(" a is %d, and b is %d\n", a, b); printf("power(2,3) returns %d.\n", power(a,b)); printf(" a is %d, and b is %d\n", a, b); return 0; } macbook:C_ch9> ./a.out a is 2, and b is 3 power(2,3) returns 8. a is 2, and b is 3 macbook:C_ch9> echo make a function to count the characters in a word make a function to count the characters in a word macbook:C_ch9> vi count_chars_in_word.c macbook:C_ch9> vi count_chars_in_word.c macbook:C_ch9> gcc count_chars_in_word.c macbook:C_ch9> ./a.out Please enter a word: 123 ^D The number of chars is 4 macbook:C_ch9> ./a.out Please enter a word: baseball^D ^D The number of chars is 9 macbook:C_ch9> ./a.out Please enter a word: baseball ^D The number of chars is 9 macbook:C_ch9> echo "baseball" | ./a.out Please enter a word: The number of chars is 9 macbook:C_ch9> cat count_chars_in_word.c /* count_chars_in_word.c To compile: gcc count_chars_in_word.c make a function to count the characters in a word in class exercise October 6, 2025 */ #include int main() { int counter = 0; int num_read = 0; char word; printf("Please enter a word: "); num_read = scanf("%c", &word); // loop while (num_read > 0) { counter++; num_read = scanf("%c", &word); } printf("\nThe number of chars is %d\n", counter); return 0; } macbook:C_ch9> exit Saving session... ...saving history...truncating history files... ...completed. Deleting expired sessions... 10 completed. Script done on Mon Oct 6 18:44:46 2025