1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "clog.h"
bool count_consecutive_chars(char ch, .......)
int main(int argc, char* argv[]) {
char* input = "aaabbcccc"; // address of the first character in the string (on the data segment)
char* pos = input; // address of the next character to look at; like a "cursor"
int num_occurrences; // will be initialized by count_consecutive_chars(…)
bool found_any = count_consecutive_chars('a', &num_occurrences, &pos);
// Always use true and false and the type bool for boolean values; do not use 1 and 0 for true/false
// Q1: What is the type of &num_occurrences?
// A1: int* --- because num_occurrences is an int, and adding a & to an expression adds a * to the type.
// num_occurrences is an int
// &num_occurrences is an int*
// Q2: What is the type of &pos?
// A2: char** --- because pos is an char*, and adding a & to an expression adds a * to the type.
// pos is a char*
// &pos is a char**
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.