I'm trying to read this .txt file:
( 1 2 ( 3 4 ( 5
with this code:
#include <stdio.h>
int main() {
  FILE* f = fopen("teste.txt", "r");
  int i;
  char j;
  while (feof(f) == 0){
    fscanf(f, "%c", &j);
    switch (j) {
      case '(':
        printf("%c ", j);
        break;
      default:
        ungetc(j,f);
        fscanf(f, "%d", &i);
        printf("%d ", i);
        break;
    }
  }
  return 0;
}
The output is:
( 1 2 2 ( 3 4 4 ( 5 5
and it should be:
( 1 2 ( 3 4 ( 5
What am I doing wrong?
 
     
    