c++ - Read line by line of file error -


i have parse data file. file has following structure:

text1.txt 1 text2.txt 2 text3.txt 4 

the file can download @ here want text1.txt , 1. code following:

#include <stdio.h> void main()  {  file    *fp= null; int     status= -1; char    name[100]; char *filename="test.txt"; fp= ::fopen(filename, "rt"); if (!fp)     {         printf("\error open: \"%s\"\n\n", filename);         return;     } { int number=0; status= fscanf(fp, "%s %d", name,number);  } while (status!= eof); } 

i using c++. problem is crashed @

status= fscanf(fp, "%s %d", name,number); 

the error " access violation writing location 0x00000000.". problem? fix me?

pass arguments scanned fscanf address :

fscanf(fp, "%s %d", name, &number); 

the compiler warned :

warning: format ‘%d’ expects argument of type ‘int *’, argument 4 has type ‘int’ [-wformat=] 

your code has undefined behavior, source of crash.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -