Home > Back-end >  C the fgets problems
C the fgets problems

Time:03-02

For utf-8 text file to read out the question, how the fgets reads not read press line,

Simple the fgets () test code:
 
#include
#include
# define MAXSTRPATH 1024
Int main ()
{
Char * cfgfile="gamp. CFG";
The FILE * fp=NULL;
Char * p, TMP/MAXSTRPATH={} '\ 0';

If ((fp=fopen (cfgfile, "r"))==NULL) {
Printf (" * * * ERROR: open the configure file failed, both please check it! \n");
return 0;
}

while (! The feof (fp)) {
TMP [0]='\ 0';
The fgets (TMP, MAXSTRPATH, fp);
Printf (" % s \ n ", TMP);

}
fclose(fp);
return 1;
}


To read the text:
# GNSS data Analysis software for Multi - constellation and Multi - frequency Precise positioning (GAMP) options

Obs file/folder=1% (0:1: file folder)
=/path
Start_time=0 2020/12/24 06:00:00. 0% (0: the from obs 1: the from inp)
End_time=0 2020/12/24 23:59:30. 0% (0: the from obs 1: the from inp)
Posmode=6% (0: SPP 6: ppp_kinematic 7: ppp_static)
Soltype=0% (0:1: the forward backward 2: combined - bf 3: combined - fb)


The actual output:
# GNSS data Analysis software for Multi - constellation and Multi - frequency Precise positioning (GAMP) options


Start_time=1 12 f: 25.00/0000/2020 03:0. 000000 3.000000:0.000000:0.000000 x/CLionProjects PPP_VS2Linux/CFG/data


Start_time=1 12 f: 25.00/0000/2020 03:0. 000000 3.000000:0.000000:0.000000

End_time 0000/2020/12 f=1:25.00 05:59. 00000 5.000000:59.000000:30.000000 osmode=6% (6:0: SPP ppp_kinematic 7: ppp_static)


Soltype=0% (0:1: the forward backward 2: combined - bf 3: combined - fb)

Extra lines and gibberish, BBS bosses to solve the problem!!!!!!

CodePudding user response:

 # include & lt; stdio.h> 
#include
# define MAXSTRPATH 1024
Int main ()
{
Char * cfgfile="gamp. CFG";
The FILE * fp=NULL;
Char * p, TMP/MAXSTRPATH={} '\ 0';

If ((fp=fopen (cfgfile, "r"))==NULL) {
Printf (" * * * ERROR: open the configure file failed, both please check it! \n");
return 0;
}

While (1) {
If (NULL==the fgets (TMP, MAXSTRPATH, fp)) break;
Printf (" % s ", TMP);
}
fclose(fp);
return 1;
}

CodePudding user response:

Miss zhao , is still the same;

# GNSS data Analysis software for Multi - constellation and Multi - frequency Precise positioning (GAMP) options

Start_time=1 12 f: 25.00/0000/2020 03:0. 000000 3.000000:0.000000:0.000000 x/CLionProjects PPP_VS2Linux/CFG/data

Start_time=1 12 f: 25.00/0000/2020 03:0. 000000 3.000000:0.000000:0.000000
End_time 0000/2020/12 f=1:25.00 05:59. 00000 5.000000:59.000000:30.000000 osmode=6% (6:0: SPP ppp_kinematic 7: ppp_static)

Soltype=0% (0:1: the forward backward 2: combined - bf 3: combined - fb)

CodePudding user response:

 d: \ test> Type gamp. CFG 
# GNSS data Analysis software for Multi - constellation and Multi - frequency Precise positioning (GAMP) options

Obs file/folder=1% (0:1: file folder)
=/path
Start_time=0 2020/12/24 06:00:00. 0% (0: the from obs 1: the from inp)
End_time=0 2020/12/24 23:59:30. 0% (0: the from obs 1: the from inp)
Posmode=6% (0: SPP 6: ppp_kinematic 7: ppp_static)
Soltype=0% (0:1: the forward backward 2: combined - bf 3: combined - fb)

D: \ test> The test
# GNSS data Analysis software for Multi - constellation and Multi - frequency Precise positioning (GAMP) options

Obs file/folder=1% (0:1: file folder)
=/path
Start_time=0 2020/12/24 06:00:00. 0% (0: the from obs 1: the from inp)
End_time=0 2020/12/24 23:59:30. 0% (0: the from obs 1: the from inp)
Posmode=6% (0: SPP 6: ppp_kinematic 7: ppp_static)
Soltype=0% (0:1: the forward backward 2: combined - bf 3: combined - fb)

D: \ test>
  • Related