Search
 
SCRIPT & CODE EXAMPLE
 

C

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 %i
", 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.
Comment

PREVIOUS NEXT
Code Example
C :: How to scale all columns in dataframe in R? 
C :: reading arrays from stdin c 
C :: synopsis of fork() 
C :: programme c qui permet de determiner si M et N sont amis ou non 
C :: man write c 
C :: Macro definition and expansion 
C :: Entering raw mode 
C :: Integer Output 
C :: send array through a pipe 
C :: c type conversion 
C :: passing an array to a function 
C :: WAP to create Database using array of structure & display it in C 
C :: Print the number 0 using write() 
C :: write a ppm image 
C :: l/O Multiple Values 
C :: how to make play a song javascript 
C :: C How to use enums for flags? 
C :: reverse number in c 
C :: transpose of a matrix in c 
C :: how to check where the last char is in a string c 
C :: robtex 
Dart :: listview.separated flutter 
Dart :: remove appbar shadow flutter 
Dart :: reverse srring in dart 
Dart :: appbar icon 
Dart :: How to add a circular dot as an indicator in Flutter Tabs? 
Dart :: flutter navigation pop 
Dart :: cannot add to a fixed-length list 
Dart :: dart string to color 
Dart :: alertdialog flutter press outside to disappera 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =