How to copy data from a pointer into a char not another pointer July 20, 2009 08:44PM | Registered: 14 years ago Posts: 405 |
Re: How to copy data from a pointer into a char not another pointer July 20, 2009 09:12PM | Registered: 15 years ago Posts: 175 |
Re: How to copy data from a pointer into a char not another pointer July 20, 2009 10:05PM | Registered: 14 years ago Posts: 703 |
char source[] = "HELLO"; char dest[6] = {0}; strcpy(dest,source); strncpy(dest,source,5); memcpy(dest,source,5);
Re: How to copy data from a pointer into a char not another pointer July 21, 2009 11:17AM | Registered: 14 years ago Posts: 405 |
Re: How to copy data from a pointer into a char not another pointer July 21, 2009 03:11PM | Registered: 15 years ago Posts: 265 |
char *string="no idea"; char X; x=*string;This will copy the first byte of the string into the variable X.
Re: How to copy data from a pointer into a char not another pointer July 21, 2009 07:04PM | Registered: 14 years ago Posts: 703 |
Quote
SteelSLasher
nothing is crashing, basically all that happens is that i copy the string and when the source pointer is nulled that char in which the string is copied to is also nulled for some reason, will try using memcpy
Re: How to copy data from a pointer into a char not another pointer July 21, 2009 09:20PM | Registered: 14 years ago Posts: 405 |
Re: How to copy data from a pointer into a char not another pointer July 21, 2009 09:59PM | Registered: 14 years ago Posts: 703 |
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 11:17AM | Registered: 14 years ago Posts: 405 |
char * redirect;
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 01:13PM | Registered: 14 years ago Posts: 379 |
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 06:34PM | Registered: 14 years ago Posts: 703 |
Quote
SteelSLasherchar * redirect;
Its declared straight after the includes, if it was not declared it would cause a compile error
If the second line is "Location: [www.google.co.uk]"
I would expect redirect to be "http://www.google.co.uk/", just to point out that this actually does work when using strcpy
here is the entire script [onsinch.pastebin.com]
#define BUFFER_SIZE (100) char redirect[BUFFER_SIZE] = {0}; .... .... if (l-10 < BUFFER_SIZE-1 && l-10 > 0) memcpy(redirect, line+10, l-10);
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 06:47PM | Registered: 14 years ago Posts: 405 |
Quote
Daid
I think you lack quite a bit of knowledge about C and strings in C. (I spot lots of ways that your code will crash) Nothing wrong with that, you'll learn as you go.
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 08:28PM | Registered: 15 years ago Posts: 276 |
char data;
char *data = malloc(size * sizeof(char));
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 10:15PM | Registered: 15 years ago Posts: 1,012 |
Quote
ekeeke
by default it points to NULL memory
Re: How to copy data from a pointer into a char not another pointer July 22, 2009 10:18PM | Registered: 14 years ago Posts: 703 |
Re: How to copy data from a pointer into a char not another pointer July 23, 2009 02:01AM | Registered: 15 years ago Posts: 265 |
Re: How to copy data from a pointer into a char not another pointer July 23, 2009 06:33AM | Registered: 15 years ago Posts: 1,012 |
Quote
henke37
Pointers (and everything else) is defined to not have a defined initial value unless you provide one.
Re: How to copy data from a pointer into a char not another pointer July 23, 2009 11:03AM | Registered: 14 years ago Posts: 405 |
Re: How to copy data from a pointer into a char not another pointer July 23, 2009 04:47PM | Registered: 14 years ago Posts: 379 |
Re: How to copy data from a pointer into a char not another pointer July 23, 2009 06:40PM | Registered: 14 years ago Posts: 703 |