How can i read some integer from file using fgets or at least cast them?
I am reading from a file like this
Code:
char master[BUFSIZ], slave[BUFSIZ], lin[BUFSIZ], col[BUFSIZ];
int nlin, ncol;
skipped code...
fgets(master,sizeof(master),fp);
// remove newline
if ((p = strchr(master, '\n')) != NULL) *p = '\0';
fgets(slave,sizeof(slave),fp);
// remove newline
if ((p = strchr(slave, '\n')) != NULL) *p = '\0';
fgets(lin,sizeof(lin),fp);
// remove newline
if ((p = strchr(lin, '\n')) != NULL) *p = '\0';
nlin = (int) lin;
fgets(col,sizeof(col),fp);
// remove newline
if ((p = strchr(col, '\n')) != NULL) *p = '\0';
ncol = (int) col;
The first two fgets works fine and then I need integers in nlin and ncol to pass on, but I dont know how to read them or cast them properly properly, now I get big numbers like 1234000 which is not right. Anybody?