Hello I am new to c programming and while trying structs with different data types in my code
#include
#include
struct myType
{
int imInteger;
float imFloat;
char imChar;
char imString[33];
};
int main()
{
struct myType mple;
example.imInteger = 4;
example.imFloat = 3.141592;
example.imChar = "h";
char exampleChar = "g";
example.imString = "Hello World";
char exampleString[33] = "Goodbye World";
printf("My data types are:\n");
printf("\t Int: %d\n", example.imInteger);
printf("\t Float: %.4f\n", example.imFloat);
printf("\t Char: %c\n", example.imChar);
printf("\t Example: %c\n", exampleChar);
printf("\t String: %s\n", example.imString);
printf("\t Example: %s\n", exampleString);
return 0;
}
I get the following error
,,error copy.c: In function 'main':
error copy.c:18:20: warning: assignment to 'char' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
18 | example.imChar = "h";
| ^
error copy.c:19:24: warning: initialization of 'char' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
19 | char exampleChar = "g";
| ^~~
error copy.c:20:22: error: assignment to expression with array type
20 | example.imString = "Hello World";
| ^
My expected output would be:
My data types are:
Int: 4
Float: 3.1416
Char: h
Example: g
String: Hello World
Example: Goodbye World
In previous codes without structs I didn't have any troubles when declaring char and using strings, so if anyone could bring me help it would be really appreciated.
Thanks
