ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I believe the purpose of line 14 is to get the size of the data from an html form, so I can initialize a buffer for the data in lines 18 & 19.
This is totally wrong! Did you ever even look up what getenv(3) is used for? It's a function from the C library which allows you to get the value (as char *) from an environment variable.
Quote:
Originally Posted by bluegospel
since "billschedContentLength+1" on line 18 designates the address location plus one, not it's size
Yes, this is ONLY the address of the string, but not the value!
Quote:
Originally Posted by bluegospel
I should rather dereference that pointer, to provide the size of "Content_Length" to malloc, so it can allocate that size of memory, assigning an address to pointer billschedBuffer.
Arggh, no! Sorry, this is not meant in an insulting way, but you seem to miss the meaning of a string aka. character pointer. If you deference the pointer, you will get the (ASCII) value of the first character. Assuming that CONTENT_LENGTH is "52", you'll get the value 53 which is the characer '5'.
Quote:
Originally Posted by bluegospel
Am I in the right ballpark?
Sorry no! But I also have the impression that you're ignoring some of the posts already written. There are a lot of hints on howto solve this problem.
So, first, are you saying the environmental variable in "Content_Length" does not correspond to the data being passed by my form?
Mhhhh, well, it could be. I don't know, because I don't know your infrastructure, meaning who is calling your program, what is the caller doing before calling your program. But it doesn't matter if the data of Content_Length corresponds to an HTML form or whatever. The fact is that you're just mishandling the char pointer. As said before, you need to convert the character stream (denoted by the char *) into a number, e.g. by using atoi(3) as already done in your code.
Originally Posted by bluegospel
billschedContentLength points to a char, according to its declaration.
Quote:
Originally Posted by bluegospel
Oh, but the manpage for getenv() indicates getenv() returns a pointer to a string.
There is no contradiction - the pointer points to the first character of the string in question.
So, to the computer, is a string actually an array of characters, such that when a variable points to a string, it actually points to the first character (the first element of the array), as in other instances of pointers to arrays?
(Pardon my narrow understanding. This is all very new to me.)
Forza, please bear with me. I have not ignored any of the posts here. I need time to sort through them all, and to study their content. Most of them are over my head, as C++ is very new to me, and my programming experience in general is very limited (which should be obvious). Please, continue to be patient with me.
A string is actually a pointer to the first character of an array of chars. The last character of a string is always 0 (not ASCII '0', but the integer 0. It's often specified as "'\0'" instead of "0" in this case.).
...
So, to the computer, is a string actually an array of characters, such that when a variable points to a string, it actually points to the first character (the first element of the array), as in other instances of pointers to arrays?
...
Yes; typically "C" strings are null-terminated, which does not contradict what you've said.
Originally Posted by bluegospel
So, first, are you saying the environmental variable in "Content_Length" does not correspond to the data being passed by my form?
Quote:
The "Length" part suggests data length, not data itself. You can print its contents, can't you ?
I'm sorry. My intent was to ask whether the environmental variable corresponds to the (length of) data being passed by my form. I thought this could be implied.
Last edited by bluegospel; 07-06-2010 at 10:20 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.