Home > Back-end >  The fgets couldn't read the file
The fgets couldn't read the file

Time:10-02


This is my function:
Int main (void)
{
Int I=0;
Char pbufs [256]="the 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]."
The FILE * fp=NULL;
Int length=0;
Int num=0;
Char buf [256]={0};
The FILE * fp_tmp=NULL;

Fp=fopen ("//the size * * *. TXT ", "wr +");//this is the path to the file;
Fp_tmp=fp;
While (I & lt; 14)
{
i++;

If (fp==NULL)
{
Printf (" open file error \ r \ n ");
return;
}

The fgets (buf, 300, fp_tmp);
Printf (" % s (% d) : in buf: % s \ n ", __FUNCTION__ and __LINE__, buf);

Fprintf (fp, "% s \ r \ n", pbufs);
}
fclose(fp);
}

Results:
* * * * * * * * * * : - $./for_test
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:
In the main [28] : buf:


This is performed after the size. TXT file contents:
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]
The 1970-01-01 02:24:51 [Error] WEB ALARM: test_str: [Log utility testing... , test_val: [12, 0 xc], BBBL abcd [123], [234]


Wonder why the fgets () to read out the contents of the file;
Please comment:

CodePudding user response:

Wrong path, the path of the slash is against, also for three star,

CodePudding user response:

reference 1st floor lhylhy response:
wrong path, the path of the slash is against, also for three asterisks,

I wrote that it was just a fuzzy path, that's not the point

CodePudding user response:

reference 1st floor lhylhy response:
wrong path, the path of the slash is against, also for three asterisks,

And that is the path under Linux, you focus points are really strange

CodePudding user response:

reference u011680603 reply: 3/f
Quote: refer to 1st floor lhylhy response:

Wrong path, the path of the slash is against, also for three asterisks,

And that is the path under Linux, you focus on the point of really strange


refer to the second floor u011680603 response:
Quote: refer to 1st floor lhylhy response:

Wrong path, the path of the slash is against, also for three asterisks,

I wrote that it was just a fuzzy path, that's not the point.

If the file path is wrong not wrong?

CodePudding user response:

reference 4 floor lhylhy response:
Quote: reference u011680603 reply: 3/f

Quote: refer to 1st floor lhylhy response:

Wrong path, the path of the slash is against, also for three asterisks,

And that is the path under Linux, you focus on the point of really strange


refer to the second floor u011680603 response:
Quote: refer to 1st floor lhylhy response:

Wrong path, the path of the slash is against, also for three asterisks,

I wrote that it was just a fuzzy path, that's not the point.

If the file path is wrong not wrong?
you really bad, admire you
  • Related