problem with using scanf for arrays

A college project required for me to do the programming in only C, so I had no choice but to use scanf...

This is only a part of my code, but I did enough tests to confirm this part was the problem

I'm supposed to write a 32-bit binary number, but when I do, the scanf doesn't disappear until I write letters on the console, and the result is not the same as what I have written in (meaning the whole a[2][2][2][2][2])..

Is it my wrong usage of scanf or is it other mistakes that I have made that's causing the problem? I hardly use scanf so I know nothing about it..

int main(){

int a[2][2][2][2][2] = {0};
int b[2][2][2][2][2] = {0};
int s[2][2][2][2][2] = {0};



scanf(" %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", &(a[1][1][1][1][1]),
&(a[1][1][1][1][0]),&(a[1][1][1][0][1]),&(a[1][1][1][0][0]),&(a[1][1][0][1][1]),
&(a[1][1][0][1][0]),&(a[1][1][0][0][1]),&(a[1][1][0][0][0]),&(a[1][0][1][1][1]),
&(a[1][0][1][1][0]),&(a[1][0][1][0][1]),&(a[1][0][1][0][0]),&(a[1][0][0][1][1]),
&(a[1][0][0][1][0]),&(a[1][0][0][0][1]),&(a[1][0][0][0][0]),&(a[0][1][1][1][1]),
&(a[0][1][1][1][0]),&(a[0][1][1][0][1]),&(a[0][1][1][0][0]),&(a[0][1][0][1][1]),
&(a[0][1][0][1][0]),&(a[0][1][0][0][1]),&(a[0][1][0][0][0]),&(a[0][0][1][1][1]),
&(a[0][0][1][1][0]),&(a[0][0][1][0][1]),&(a[0][0][1][0][0]),&(a[0][0][0][1][1]),
&(a[0][0][0][1][0]),&(a[0][0][0][0][1]),&(a[0][0][0][0][0]));
I don't know why you would represent a 32 bit binary number as a 5 dimensional array. That has to be about as far from convenient as you can get.

%d reads a numeric value from the input stream. If there is more than one consecutive digit in the stream, and that value can be held in a single int, that's what will happen. You would run into the same problem with cin in C++.

Read your number in as a string, and convert the string to whatever representation you're using.
Topic archived. No new replies allowed.