Reading data from Arduino via c++

I am trying to read serial data from arduino via a c++ program.The arduino program generates random numbers and i am trying to print these numbers on my c++ terminal. Below is the c++ code

#include<stdio.h>

int main()
{
FILE *serial;
serial=fopen("/dev/ttyACM0","r");
int datread;
while(1){
    fscanf(serial,"%d",&datread);
    printf("%d\n",datread);
}
return 0;
}

This is the output 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097 22097

The arduino generates random numbers and this is the output i'm getting on my c++ terminal.
Thanks

Do you think it might help if you posted your Arduino code ?

No, it didnĀ“t.

You never check the return value of fscanf. scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s - cppreference.com

i'm curious -- what is a c++ terminal?
(what does a terminal have to do with a programming language)?

This type of terminal type works in class rooms only :nerd_face: