You are not reading in the binary strings a
and b
correctly (hint: scanf("%d",&x)
reads an entire int
at a time, not just a single digit from an integer).
1 Like
hello sir, what can i do to correct this error ?
Read the bits a character at a time, and convert to 0
or 1
as appropriate.
For example, for reading a
(I suck at C
, so it there’s a better way, please let me know):
for(j=0;j<n;j++)
{
char bitChar;
scanf(" %c",&bitChar);
a[j] = bitChar - '0';
}
See e.g. How to do scanf for single char in C - Stack Overflow
Edit:
C++ solution, just for fun
2 Likes
thanks a lot !
1 Like
There is a better way. You can use a string input
char A[500]
scanf("%s", &A);
and then subtract ‘0’ from each input.
I used to study C years ago but as far as i remember this takes a string input as long as there is no space in between.