Home > Back-end >  How c from TXT read the Numbers, and assign a value to variable
How c from TXT read the Numbers, and assign a value to variable

Time:09-22

Hypothesis 1. TXT for the content of the 1
How to put the 1 assign a value to a variable

CodePudding user response:

Fopen to open the file, then read fread to variables such as I, fread (& amp; I,...

CodePudding user response:

reference 1/f, Simple, Soft reply:
fopen to open the file, then read fread to variables such as I, fread (& amp; I,...


Are there any specific instances, small white said don't understand

CodePudding user response:

1. TXT FILE * FILE=fopen (" ", "rb");
int i;
Fread (& amp; I, sizeof (int), 1, file);
The fclose (file);

CodePudding user response:

May I have an baidu fscanf

CodePudding user response:

The
reference 4 floor CHXCHXKKK reply:
can baidu fscanf

Fscanf tried not

CodePudding user response:

After direct fread by atoi not ok,,,

CodePudding user response:

Reading and writing configuration generally use ini files, have special API GetPrivateProfileString (); WritePrivateProfileString ();

CodePudding user response:


The small white or start with ini configuration file to read,

CodePudding user response:

Fscanf () function to read data from the stream (stream), and the data stored in the specified variable, for the specific way of using this function, please refer to the
"The scanf printf and series c + + functions introduction"
Wish I could help you!

CodePudding user response:

refer to 6th floor light bamboo hat reply:
fread directly after use atoi no,,,

 # include 

Int main ()
{
1. TXT FILE * FILE=fopen (" ", "rb");
Char ch_tmp [1024].
Fread (ch_tmp, 1024, 1, file);
Int num=atoi (ch_tmp);
The fclose (file);
Printf (" num=[% d] \ n ", num);
Return (0);
}

  • Related