Here is the logic what I am trying to do;
- get input char with fgetc() in the variable named ch,
- check if not ch is EOF or equal to '\n',
- increase int variable named counter,
- then put the variable ch to stdin using ungetc()
- repeat process
After that, allocate the memory with counter. Again, get char in stdin, using fgetc() and store it into array.
This thought is working with only one char input. This is the code I wrote for two or more inputs;
while ( ((entry = fgetc(stdin)) != EOF) && (entry != '\n'))
{
++counter;
ungetc(entry, stdin);
fprintf(stdout, "%c,%d ", entry, counter); //
} //;
This is the output of console when I enter qwert as an input;
q,2 q,3 q,4 q,5 q,6 q,7 q,8 q,9 q,10 q,11 q,12 q,13 q,14 q,15 q,16 q,17 q,18 q,19 q,20 q,21 q,22 q,23 q,24 q,25 q,26 q,27 q,28 q,29 q,30 q,31 q,32 q,33 q,34 q,35 q,36 q,37 q,38 q,39 q,40 q,41 q,42
After read first char it keeps reading first character never gets second or others.
Os : Windows 10 | MinGW gcc-9.1.0
What am I doing wrong? Is it even possible?