#how i can check if in scanf i got an integer and not a char

10 messages · Page 1 of 1 (latest)

drifting parrot
#
 displayPuzzle(gr, st, pinakas, numbers, op, snum, pdis, test);
    test = 1;
    int check = 1;
    do
    {
        do
        {
            printf("\nEnter your command in the following format:\n");
            printf("i,j=val: for entering val at position (i,j)\n");
            printf("0,0=0 : for saving and ending the game\n");
            printf("Notice: i,j,val numbering is from [1..%d]\n", pdis);

            if (scanf("%d%c%d%c%d", &i, &kom, &j, &ison, &val) != check)
            {
                printf("Wrong format try again2\n");
                check = 0;
                break;
                
            }
            else if (kom != ',' || ison != '=' || i > pdis || i < 0 || j > pdis || j < 0 || val > pdis || val < 0)
                {
                    printf("Wrong format try again1\n");
                }

        } while (kom != ',' || ison != '=' || i > pdis || i < 0 || j > pdis || j < 0 || val > pdis || val < 0);
        if (check != false)
        {
            numbers[i - 1][j - 1] = val;
            printf("Value inserted!\n");
        }
        printf("***This is not a valid Kenken puzzle***\n");
        displayPuzzle(gr, st, pinakas, numbers, op, snum, pdis, test);

    } while (i != 0 && j != 0 && val != 0);

if my input is aaaaa it becomes an infinity loop

native flaxBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

sinful adder
drifting parrot
#

this is what is happening

#

@sinful adder

drifting parrot
#

i did it like this

#
 scanf("%s", input);
            i=atoi(input);
            input[0]=input[2];
            kom=input[1];
            j=atoi(input);
           input[0]=input[4];
            ison=input[3];
            val=atoi(input);
#

!solved

native flaxBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] how i can check if in scanf i got an integer and not a char