0

The last thing shouldn't be there, it should show only the numbers,can someone tell me why this happens? When I put for example char [5] = "12345"; it works just fine and remove the if in the fors

   for (k = 0; k < 12; k++)
{
        c[k] = 'g';
        printf("%", c[k]);
}
printf("input:");
scanf("%s", c);
int j, i;

    unsigned int pat;
    for (j = 0; j <5; j++) 
    {
        for (i = 0; i < 12; i++)
        {
            if (c[i+1]!='g')
            {

                pat = get_row_pattern(c[i], j);
                print_bits(pat, NUM_COLS + 1);

            }


        }
        print_char('\n');
    }

Thanks

3
  • Is this your complete code? Commented Oct 21, 2013 at 23:58
  • no, its not but the other part is given code for assignment and that's why I haven't added it here Commented Oct 22, 2013 at 0:01
  • Your question is not clear enough. Commented Oct 22, 2013 at 0:02

1 Answer 1

2

In your example with 123, scanf will overwrite the first 4 elements of the c array with the characters '1', '2', '3', and a zero. You may want to change your program logic to not print anything if the array element is '\0'.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I changed c[k] in the first for to be equal to '\0' and it worked perfectly, thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.