Atoi() is the C runtime library function for converting the ASCII representation of a number to an integer
Anything related to C or C++ standard library functions `fgets` (C) or `std::fgets` (C++)
So here fgets is reading more than one integer at a time from file so atoi is not getting the int too
C- Reading from a file and getting unexpected results when printing contents of it
Uggested solution use fgets to read i into a buffer then atoi or strtol to convert a buffer to an integer;or you could do an extra fgets after scanf or getchar in a loop until you ve read a newline but seriously the fgets solution is a lot more robust and worth learning now.
Issue with scanf() function in c?