473,396 Members | 1,773 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,396 software developers and data experts.

How to call A variable parameter function

I have written a variable parameter function:
APR_DECLARE_NONSTD(apr_status_t) sas_strcat(char *buffer,size_t *
buffer_len ,... )
{
char *cp, *argp;
apr_size_t saved_lengths[MAX_SAVED_STR_LENGTHS];
apr_size_t total_len;
int nargs = 0;

/* Pass one --- find length of required string */

apr_size_t len = 0;
va_list adummy;

va_start(adummy, buffer_len );

while ((cp = va_arg(adummy, char *)) != NULL) {
apr_size_t cplen = strlen(cp);
if (nargs < MAX_SAVED_STR_LENGTHS) {
saved_lengths[nargs++] = cplen;
}
(apr_status_t) len += cplen;
}

va_end(adummy);

total_len = len ;
/* Allocate the required string */
if ( len *buffer_len + 1)
return APR_ENOMEM;

cp = buffer;

/* Pass two --- copy the argument strings into the result space */

va_start(adummy, buffer_len );

nargs = 0;
while ((argp = va_arg(adummy, char *)) != NULL) {
if (nargs < MAX_SAVED_STR_LENGTHS) {
len = saved_lengths[nargs++];
}
else {
len = strlen(argp);
}
//Possible copy it to itself
//example: filename=strcat(filename,"_001","_002",NULL);
//maybe need not , VC memcpy do check overlap
memmove(cp, argp, len);
cp += len;
}

va_end(adummy);
*buffer_len = total_len+1;
*cp = '\0';
return APR_SUCCESS;
}

Now I want to add a function like
sas_strcat_with_enter(char *buffer,size_t * buffer_len ,... )

every thing is as same as the sas_strcat,except for this function will
add a "\n" and the end of string.
how can i make such funtions by calling the sas_strcat from within the
sas_strcat_with_enter function

Thanks.

Apr 28 '07 #1
2 3728
On Apr 28, 2:46 am, CFAN <eyeli...@gmail.comwrote:
I have written a variable parameter function:
It's called a "variadic function".
APR_DECLARE_NONSTD(apr_status_t) sas_strcat(char *buffer,size_t *
buffer_len ,... )
I'm guessing the APR_DECLARE_NONSTD is a macro which
expands to something useful on your system. For posts
here, it would help to either provide that definition or
remove invocations of it in posted code.
Now I want to add a function like
sas_strcat_with_enter(char *buffer,size_t * buffer_len ,... )

every thing is as same as the sas_strcat,except for this function will
add a "\n" and the end of string.
how can i make such funtions by calling the sas_strcat from within the
sas_strcat_with_enter function
You can't. But you can write a function that takes a va_list as
an argument and does all the work, and then have both
sas_strcat_with_unix_newline() and sas_strcat() call that function.
Apr 28 '07 #2
CFAN <ey******@gmail.comwrites:
I have written a variable parameter function:
APR_DECLARE_NONSTD(apr_status_t) sas_strcat(char *buffer,size_t *
buffer_len ,... )
<snip>
Now I want to add a function like
sas_strcat_with_enter(char *buffer,size_t * buffer_len ,... )

every thing is as same as the sas_strcat,except for this function will
add a "\n" and the end of string.
how can i make such funtions by calling the sas_strcat from within the
sas_strcat_with_enter function
You wait months for a question about variadic functions to come along
and then two turn up in as many days...

This must have happened before because it is a FAQ (no. 15.12):

http://c-faq.com/varargs/handoff.html

--
Ben.
Apr 29 '07 #3

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

Similar topics

1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
6
by: komal | last post by:
hi all basically my problem is i have to write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function...
26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
5
by: Matt Clepper | last post by:
Any way to do this? I need to call functions based on a variable. Do I actually have to make a case statement and call each funciton explicitly, or is there any way to call a function where the...
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
1
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
0
by: Mike S | last post by:
I've seen examples of using the CallWindowProc Windows API function to call functions through their addresses in VB6 -- a clever workaround to emulate C-like function pointer semantics. A...
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
2
by: savio XCIX | last post by:
I created the following stored procedure: ======= CREATE PROCEDURE TBLNAME.proc_test (IN p_custnum VARCHAR(8), IN p_zipcode...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.