Home > Back-end >  C. How to read Chinese characters from the text to the structure?
C. How to read Chinese characters from the text to the structure?

Time:09-27

Will read in a list to the structure, if read, in the form of fscanf % s is garbled! This should be how to read Chinese characters from TXT text

CodePudding user response:

Look at your file format, and post your code

CodePudding user response:

Save the file in binary format, and then try to read in binary format

CodePudding user response:

The
refer to the original poster m0_46235144 response:
to read in a list to the structure, if use fscanf % s is read, in the form of the code! This should be how to read Chinese characters from TXT text

#include
#include
# define MAX 1024
Struct student
{
Int no;
Char name [30].
Char dao [30];
} stu [29].
Int main ()
{
The FILE * fp.
If ((fp=fopen (" C: \ \ Users \ \ 47390 \ \ Desktop \ \ list. TXT ", "r"))==NULL)
{
Printf (" positioning failure ");
getchar();
exit(0);
}
Int a [30]={0}, I=0;
Char STR [30].

for(i=0; I<29. I++)
{
The fscanf (fp, "% d % s", & amp; A [I], & amp; Stu [I] name);
Stu [I]. No=a, [I].
The fgets (STR, sizeof (STR), fp);

Printf (" % d % s \ n ", a [I], stu [I] name);
}




return 0;
}

CodePudding user response:

The
reference 1/f, confident boy reply:
look at your file format, in addition to stick out your code

Thank you for reminding me, the first post has no experience

CodePudding user response:

First statement I also don't understand ah, I don't how to use the console, casually say
You wrote in a text file, all is the text, then read it out structure is how is it possible? Sorry if it is a UNICODE, need in the file to 0 xfeff, then there would be no garbage,

CodePudding user response:

Text file is saved in the form of a string, first read string, printing, to ensure that the read data is correct,
And then converted to need data types,
  • Related