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]);
}
countcount >= 50. Also why do you store the chars as ints?countto zero inside the loop? It will now just setsafe[0]to i. You must increment it:safe[count++]= i;countreaches 50, you should also break out wheniequalsEOF. Also,safe[]can use typecharinstead ofintto save space.