LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2010, 12:29 PM   #16
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454

[QUOTE=bluegospel;4024426]Sergei, the excerpt you most recently posted is actually from the tutorial I'm using as a model.

Here are my lines, corresponding to the lines you reference from the model:

Code:
14 char* billschedContentLength = getenv("CONTENT_LENGTH");

18 billschedBuffer = malloc(billschedContentLength+1); // allocate a buffer
I believe the purpose of line 14 is to get the size of the data from an html form .../QUOTE]

So in which form, i.e. as item of which type/kind, do you get the size ?
 
Old 07-05-2010, 12:40 PM   #17
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
billschedContentLength points to a char, according to its declaration.
 
Old 07-05-2010, 12:43 PM   #18
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
Oh, but the manpage for getenv() indicates getenv() returns a pointer to a string.
 
Old 07-05-2010, 12:43 PM   #19
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by bluegospel View Post
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 View Post
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 View Post
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 View Post
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.

Andi
 
Old 07-05-2010, 01:14 PM   #20
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
So, first, are you saying the environmental variable in "Content_Length" does not correspond to the data being passed by my form?
 
Old 07-05-2010, 01:20 PM   #21
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by bluegospel View Post
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.

Andi
 
Old 07-05-2010, 01:22 PM   #22
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by bluegospel View Post
billschedContentLength points to a char, according to its declaration.
Quote:
Originally Posted by bluegospel View Post
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, back to our sheep - 'malloc' requires what as an argument and and what do you give it ?
 
Old 07-06-2010, 09:28 AM   #23
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
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.)
 
Old 07-06-2010, 09:32 AM   #24
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
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.
 
Old 07-06-2010, 09:34 AM   #25
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Yes.

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.).
 
Old 07-06-2010, 09:35 AM   #26
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
Can someone please direct me to the page describing the different tags to offset excerpts in these forums?
 
Old 07-06-2010, 09:42 AM   #27
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by bluegospel View Post
...
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.
 
Old 07-06-2010, 09:44 AM   #28
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by bluegospel View Post
So, first, are you saying the environmental variable in "Content_Length" does not correspond to the data being passed by my form?
The "Length" part suggests data length, not data itself. You can print its contents, can't you ?
 
Old 07-06-2010, 09:47 AM   #29
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Use post reply, not quick reply and you will see a number of icons representing tags. Mouse over them to see a description
 
Old 07-06-2010, 10:19 AM   #30
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Original Poster
Rep: Reputation: 53
Quote:
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.
 
  


Reply

Tags
c++, executable, execute, form, program


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors, Errors, and more Errors (KDE 3.4.x GUI Errors) Dralnu Linux - Software 2 05-13-2006 08:30 AM
Qt errors devit Programming 1 02-09-2004 03:45 PM
Errors during filesystem check with one kernel while no errors with other kernel Potentials Linux - General 11 12-30-2003 04:24 AM
QMAIL errors errors.. YourForum Linux - Software 0 11-27-2003 12:30 PM
2 many errors wesley Linux - Newbie 1 08-02-2001 11:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration