I'm trying to ask a user to enter two binary sequences and check if they are valid. here is my code.
char seq1[8], seq2[8];
printf("Enter 1st 8-bit sequence: ");
scanf("%8s", seq1);
getchar();
printf("\nEnter 2nd 8-bit sequence: ");
scanf("%8s", seq2);
getchar();
printf("\n");
printf("%s\n", seq1);
printf("%s\n", seq2);
if(strlen(seq1) < 8 || strlen(seq2) < 8){
printf("Error: must enter 8-bits\n");
exit(1);
}
for(int i = 0; seq1[i]!='\0'; i++){
if(seq1[i]>48||seq1[i]<49){
printf("Error: non-binary detected\n");
exit(1);
}
}
for(int i = 0; seq2[i]!='\0'; i++){
if(seq2[i]>48||seq2[i]<49){
printf("Error: non-binary detected\n");
exit(1);
}
}
When printing the strings I get the second string (seq2) added onto the end of seq1, and it always comes back as "Non-binary detected" even if it's all 1's and 0's.