Answers for "input multipal data types"

C
0

input multipal data types

Your prompt says "Enter four ints", but you haven't declared any variables of type int. You have

unsigned char minx[1024], x, y, z;
which gives you one array of 1024 unsigned chars, and three individual unsigned chars.

You then wrote

scanf( "%s %x %c %i", &minx, &x, &y, &z);
You said you didn't get any compiler errors. If possible, I have to encourage you to get a better compiler! Mine warned me about all sorts of things on this line:

format specifies type 'char *' but the argument has type 'unsigned char (*)[1024]'
format specifies type 'unsigned int *' but the argument has type 'unsigned char *'
format specifies type 'int *' but the argument has type 'unsigned char *'
If you want to enter a string, a hexadecimal integer, a character, and another integer, make your variable types match:

char str[100];
int hex;
char c;
int anotherint;

scanf("%99s %x %c %i", str, &hex, &c, &anotherint);

printf("You wrote: %s %x %c %in", str, hex, c, anotherint);
I used %99s to make sure I didn't overflow char str[100].

Also, notice that you do not need & before str in the scanf call.
Posted by: Guest on February-18-2022

Code answers related to "C"

Browse Popular Code Answers by Language