0

Hello, I am using strncpy to copy the first line of a multi-line buffer. I have successfully found the amount of characters to the end of the first line, and I have performed a strncpy to copy the first line of the buffer to a char *.

However, some of the characters are being copied incorrectly.

For example, I am trying to copy:

GET http://en-gb.start2.mozilla.com/firefox?client=firefox-a&rls=org.mozilla:en-GB:official HTTP/1.1 
Host: en-gb.start2.mozilla.com

But the first line is copied as:

GET http://en-gb.start2.mozilla.com/firefox?client=firefox-a&rls=org.[B]mozillbÛ¿¸aÛ¿:official[/B] HTTP/1.1

Or as:

GET http://en-gb.start2.mozilla.com/firefox?client=firefox-a&rls=org.[B]mozillLþ¿ÿ-GB:official[/B] HTTP/1.1

(bold = problem)


How can I fix this problem?

Thank you in advance,
Matthew

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by fpsasm
0

The problem is that there is no guarantee that strncpy will put a \0 at the end of the string.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.