Skip to main content
deleted 6 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff has writtenwrote code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the contents of the memory location indicated by length. Let's suppose the number there is 100.
  2. Then the expression is evaluated, the result of 100 is still 100.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;

If this answers your question, please click the check mark to accept it.

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff has written code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the contents of the memory location indicated by length. Let's suppose the number there is 100.
  2. Then the expression is evaluated, the result of 100 is still 100.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;

If this answers your question, please click the check mark to accept it.

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff wrote code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the contents of the memory location indicated by length. Let's suppose the number there is 100.
  2. Then the expression is evaluated, the result of 100 is still 100.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;

If this answers your question, please click the check mark to accept it.

deleted 60 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff has written code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the contents of the memory location indicated by length. Let's suppose the address number there is 1000100 (I'm writing it in decimal instead of hex to facilitate).
  2. Then the expression is evaluated, the result of 1000100 is still 1000100.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;

If this answers your question, please click the check mark to accept it.

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff has written code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the memory location indicated by length. Let's suppose the address number there is 1000 (I'm writing it in decimal instead of hex to facilitate).
  2. Then the expression is evaluated, the result of 1000 is still 1000.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff has written code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the contents of the memory location indicated by length. Let's suppose the number there is 100.
  2. Then the expression is evaluated, the result of 100 is still 100.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;

If this answers your question, please click the check mark to accept it.

Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

Your code is almost functional, but you're forgetting one thing and you have two errors.

What you're forgetting

You need to transfer to *content each byte you're putting inside c. Otherwise you'll simply overwrite c hundreds of times for nothing.

Errors:

The first and most obvious error is that you shouldn't free() the content, otherwise you'll lose it. The staff has written code in main() that will do the job of freeing content when the server no longer needs it.


The second and more subtle error is that warning the compiler is giving you about the length.

That happens because *length++ is not doing what you think. It's doing this:

  1. The dereference (*) happens first, giving you the memory location indicated by length. Let's suppose the address number there is 1000 (I'm writing it in decimal instead of hex to facilitate).
  2. Then the expression is evaluated, the result of 1000 is still 1000.
  3. The result is thrown away (you aren't doing anything with it).
  4. length is then incremented AFTER the evaluation. It's changing where the pointer is pointing to, not what it's pointing at.

It is effectively the same as doing this:

*length;
length = length + 1;

So the fix would be either:

  1. use (*length)++ instead of *length++ to override the order of preference between the * operator and the ++.
  2. go the simple way and use *length += 1; or *length = *length + 1;