473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Passing String to Function

I'm sure this is newbie but I've done some searching on this and
haven't found the exact same situation. Basically, I'm trying to pass a
string to a function where it get's built up (it's supposed to be a
where clause for a a database query) and in the called function it
get's built up with malloc as necessary. The problem is, I can't get it
to have the proper value when it comes back to the called function.
Initially, it's just a pointer to char. Can anyone point me to an FAQ
or some such ? Thanks...

Dec 31 '05 #1
3 3512
jc******@rochester.rr.com wrote:
I'm sure this is newbie but I've done some searching on this and
haven't found the exact same situation. Basically, I'm trying to pass a
string to a function where it get's built up (it's supposed to be a
where clause for a a database query) and in the called function it
get's built up with malloc as necessary. The problem is, I can't get it
to have the proper value when it comes back to the called function.
Initially, it's just a pointer to char. Can anyone point me to an FAQ
or some such ? Thanks...


Try changing the * to a ** on line 42. Or, in other words, how can we
tell you what you have done wrong if you don't show us what you have done?

You might find this FAQ useful though:
http://c-faq.com/ptrs/passptrinit.html
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 31 '05 #2
On 31 Dec 2005 06:54:14 -0800, in comp.lang.c ,
"jc******@rochester.rr.com" <jc******@rochester.rr.com> wrote:
I'm sure this is newbie but I've done some searching on this and
haven't found the exact same situation. Basically, I'm trying to pass a
string to a function where it get's built up


Post some sample of your code. Its impossible to diagnose it via
crystal ball...
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 1 '06 #3
If you're building up a new block block of data based on the contents
of the passed pointer, you shouldn't be using locally defined
(automatic) variables. Instead you should be using malloc to allocate
memory from the heap and return a pointer to the newly allocated area;
or preferably pass an additional argument to your function that is the
address of memory you've allocated for it to store it's results in. The
former lends itself to memory leaks if you're not diligent whereas the
latter usually goes along with better memory management practices
(doesn't mean you are immune to leaking if you forget to free() it as
well, however).

Jan 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob | last post by:
My understanding of the image string function is this, that it allows the display of text in Graphics As per the parameters it receives: ImageString($image,6,$xpos,$ypos,$out,$col) these...
4
by: Suddn | last post by:
Help me get my mind around passing string types to a function. I need to have the function modify the string types and get them back. Normaly I would just return the modified string but I need to...
3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
3
by: DP | last post by:
I am trying to use the string or string$ (I don't know the difference) function to convert a number to string, but I do not know what the obligatory arguments 2nd & 3d stand for. Thanks for your...
4
by: Ralph Noble | last post by:
Does anyone know of a string function in Access that will allow me to count the number of instances one string occurs within another? Or if there is some sort of word count function? If there is,...
23
by: David Frank | last post by:
How can I write a string function that encloses the input string in quotes "string" ?? below works for the "123 operation but adding " to it clobbers the "123 main() { char...
1
by: muntyanu | last post by:
Hi all, I am passing string from C++ to C# but not sure which way is more correct. Here it is: First approach: CDAnetCSharpHooks::PassString( ) { char str = "String to pass"; DotNetObject...
5
by: JR | last post by:
I am having trouble remembering a string function that I used a while back in VB. I don't know if it was .NET specific. The function either searched a string or replaced a substring in a string...
2
by: rn5a | last post by:
All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that are available in ASP are supported by ASP.NET as well except for the string function 'String'. The 'String' function takes...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.