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 36 37 38 39 40 41 42 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "clog.h"
// STRUCT TYPE DEFINITION for `struct Location`
struct Location {
int latitude; // `latitude` is a field within the type `struct Location`
int longitude; // `longitude` is a field within the type `struct Location`
char* name;
}; // <<<<< DO NOT FORGET THIS SEMICOLON <<<<<
int main(int argc, char* argv[]) {
struct Location favorite = {.latitude = 40,
.longitude = -86,
.name = "NAME",
.reason = "REASON" };
printf("My favorite Location is %s at (%d, %d) because %s\n",
favorite.name,
favorite.longitude,
favorite.latitude,
favorite.reason
);
return EXIT_SUCCESS;
}
/*
struct_3.c: In function ‘main’:
struct_3.c:18:10: error: ‘struct Location’ has no member named ‘reason’
.reason = "REASON" };
^~~~~~
struct_3.c:18:22: warning: excess elements in struct initializer
.reason = "REASON" };
^~~~~~~~
struct_3.c:18:22: note: (near initialization for ‘favorite’)
struct_3.c:23:11: error: ‘struct Location’ has no member named ‘reason’
favorite.reason
^
*/
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2021 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.