Home > Back-end >  Why not stop at the '='?
Why not stop at the '='?

Time:11-14

String manipulation, thank you

CodePudding user response:

I look at you this code is very don't understand, why didn't you buf and pkey allocated space also can be directly use?

CodePudding user response:

This program you can run,,, the memory of crossing the line, a pointer can't save something, or defined as a char array, or use malloc dynamic allocation

CodePudding user response:

reference 1st floor NorZ response:
you very don't understand, I looked at the code you buf and why didn't the pkey allocate space can also directly use?

* (pkey + pos)=* (buf + pos); As a result,

CodePudding user response:

quoted Chen reply: 3/f
Quote: refer to 1st floor NorZ response:
I looked at the code is very don't understand, you why didn't you buf and pkey allocated space also can be directly use?

* (pkey + pos)=* (buf + pos); As a result, the


. Is not the problem, I don't understand is your buf is a pointer, not allocate memory, pkey is also, why can run up, what is the compiler and runtime environment? You perform CFG the binaries, you compiled code?

CodePudding user response:

Itself, logic code, no problem, than the pkey assignment a space, the impact is not big, is why can perform, I wonder

CodePudding user response:

NorZ
reference 4 floor response:
Quote: quoted Chen reply: 3/f
Quote: refer to 1st floor NorZ response:
I looked at the code is very don't understand, you why didn't you buf and pkey allocated space also can be directly use?

* (pkey + pos)=* (buf + pos); As a result, the


. Is not the problem, I don't understand is your buf is a pointer, not allocate memory, pkey is also, why can run up, what is the compiler and runtime environment? You perform CFG the binaries, you compiled code?

Buf in the fgets function allocates memory, the pkey and buf points to the same string?

CodePudding user response:

refer to 6th floor Chen reply:
Quote: refer to 4th floor NorZ response:
Quote: quoted Chen reply: 3/f
Quote: refer to 1st floor NorZ response:
I looked at the code is very don't understand, you why didn't you buf and pkey allocated space also can be directly use?

* (pkey + pos)=* (buf + pos); As a result, the


. Is not the problem, I don't understand is your buf is a pointer, not allocate memory, pkey is also, why can run up, what is the compiler and runtime environment? You perform CFG the binaries, you compiled code?

Buf in the fgets function allocates memory, the pkey and buf points to the same string?


The key you no such assignment operation... You give the pkey is inferior to the end of the cycle (pos) assignment '\ 0' print to see again, or the end of the loop to print the value of the pos, to determine whether is not!='=' stuck

CodePudding user response:

Pkey is wild pointer, didn't see it points to can read and write the normal area of memory, also have no malloc, how can you use?
Even if can use, but can't guarantee all ~

And the pkey can even point to a read/write memory, then met '=' no '\ 0', % s output will continue to back output, until meet '\ 0'

CodePudding user response:

refer to 6th floor Chen reply:
Quote: refer to 4th floor NorZ response:
Quote: quoted Chen reply: 3/f
Quote: refer to 1st floor NorZ response:
I looked at the code is very don't understand, you why didn't you buf and pkey allocated space also can be directly use?

* (pkey + pos)=* (buf + pos); As a result, the


. Is not the problem, I don't understand is your buf is a pointer, not allocate memory, pkey is also, why can run up, what is the compiler and runtime environment? You perform CFG the binaries, you compiled code?

Buf in the fgets function allocates memory, the pkey and buf points to the same string?

Haven't seen the pkey point to buf operation

CodePudding user response:

references 9/f, confident boy reply:
Quote: refer to the sixth floor Chen reply:
Quote: refer to 4th floor NorZ response:
Quote: quoted Chen reply: 3/f
Quote: refer to 1st floor NorZ response:
I looked at the code is very don't understand, you why didn't you buf and pkey allocated space also can be directly use?

* (pkey + pos)=* (buf + pos); As a result, the


. Is not the problem, I don't understand is your buf is a pointer, not allocate memory, pkey is also, why can run up, what is the compiler and runtime environment? You perform CFG the binaries, you compiled code?

Buf in the fgets function allocates memory, the pkey and buf points to the same string?

Haven't seen the pkey point to buf operation?

FREEBSD CC
  • Related