int array doesnt get char values

Posted by user1780004 on Stack Overflow See other posts from Stack Overflow or by user1780004
Published on 2012-10-27T22:19:36Z Indexed on 2012/10/27 23:01 UTC
Read the original article Hit count: 146

Filed under:

I am absolutely brand new at programming and im not sure how to explain what im doing here.

The whole purpose of this piece is to enter values and then print them out in the same order. Now I wanna quit from entering values when pressing 'q' and so I have to scanf for chars but when I assign them back to the int array the values are not the same.

Hope that makes any sense to you but in any case heres my code:

#include <stdio.h>
#include <stdlib.h>
#define SIZE  5000
define flush fflush(stdin)

main() {
    int input[SIZE] = {0},i = 0;
    int counter = 0;
    char inputs, quit;

     do {
        system("cls");
        printf("Input number ('q' to quit and display numbers entered): ");

        flush;
        scanf("%c",&inputs);
        flush;

        if (inputs == 'q')
            quit = 'q';
        else {
            input[i] = inputs;
            counter++;
            i++;
        }
    } while (i < SIZE && quit != 'q');

    for(i = 0; i < counter; i++){
        printf("%i.%i\n", i + 1, input[i]);
    }

    system("pause");
}

Ive been trying to do this on my own btw and also researched some information online regarding chars but couldnt find anything that would help me. Thanks a lot in advance.

© Stack Overflow or respective owner

Related posts about c