Quantcast
Channel: Save whole input in integer array (read with getchar) - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Save whole input in integer array (read with getchar)

$
0
0

I'm only allowed to use the stdio.h library. So I want to read the user input with getchar until the first "/" and then want to save the read input in an integer array. Checking the input out of the while-loop, i recognized that only the last string is safed.

For example I type in "test/hello", I want to safe "test" in the integer array called "safe" so that I can work with it out of the while-loop too.

I have checked the input out of the while-loop with "putchar(safe[count]);" but the only safed input is the letter "t". (Based on the example above)

    #include <stdio.h>

    int count;
    char i;
    int safe[50];

    int main() {
        while (1) {
            i = getchar();
            count = 0;
            if (i == '/')
                break;
            safe[count] = i;
        }
        // putchar(safe[count]);
     }

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images