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 30 31 32 33 34 35 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// BUGGY
void print_one_char_from_string(char* s, int idx_to_print) {
printf("%c\n", s[idx_to_print]);
}
int main(int argc, char* argv[]) {
// BUG passing a char to a function that takes a char*
print_one_char_from_string('A', 15); // <<<<<<<<<<<<< BUG <<<<<<<<<<<<<<
// "passing argument 1 of ‘print_one_char_from_string’ makes «ADDRESS» from integer
// without a cast
// “expected ‘char *’ but argument is of type ‘int’”
// SOLUTION: Figure out the type of your argument (the thing you are passing) and
// the type of the function's parameter (specification of what it expects.
return EXIT_SUCCESS;
}
/*
d.c: In function ‘main’:
d.c:13:29: warning: passing argument 1 of ‘print_one_char_from_string’ makes pointer from integer without a cast [-Wint-conversion]
print_one_char_from_string('A', 15);
^~~
d.c:7:39: note: expected ‘char *’ but argument is of type ‘int’
void print_one_char_from_string(char* s, int idx_to_print) {
~~~~~~^
/bin/bash: line 1: 38875 Segmentation fault (core dumped) ~/d.c.temp
*/
/* 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.