Categories:
.NET (357)
C (330)
C++ (184)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (2)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
I have a pre-ANSI compiler, without stdarg.h What can I do?
I have a pre-ANSI compiler, without stdarg.h What can I do?
✍: Guest
There's an older header, <varargs.h>, which offers about the same functionality.
Here is the vstrcat function, rewritten to use <varargs.h>:
#include <stdio.h>
#include <varargs.h>
#include <string.h>
extern char *malloc();
char *vstrcat(va_alist)
va_dcl /* no semicolon */
{
int len = 0;
char *retbuf;
va_list argp;
char *p;
va_start(argp);
while((p = va_arg(argp, char *)) != NULL) /* includes first */
len += strlen(p);
va_end(argp);
retbuf = malloc(len + 1); /* +1 for trailing \0 */
if(retbuf == NULL)
return NULL; /* error */
retbuf[0] = '\0';
va_start(argp); /* restart for second scan */
while((p = va_arg(argp, char *)) != NULL) /* includes first */
strcat(retbuf, p);
va_end(argp);
return retbuf;
}
(Note that there is no semicolon after va_dcl. Note that in this case, no special treatment for the first argument is necessary.) You may also have to declare the string functions by hand rather than using <string.h>.
If you can manage to find a system with vfprintf but without <stdarg.h>, here is a version of the error function using <varargs.h>:>
#include <stdio.h>
#include <varargs.h>
void error(va_alist)>
va_dcl /* no semicolon */>
{>
char *fmt;>
va_list argp;>
fprintf(stderr, "error: ");>
va_start(argp);>
fmt = va_arg(argp, char *);>
vfprintf(stderr, fmt, argp);>
va_end(argp);>
fprintf(stderr, "\n");>
}>
>
(Note that in contrast to <stdarg.h>, under <
2015-06-10, 1648👍, 0💬
Popular Posts:
When should the register modifier be used? Does it really help? The register modifier hints to the c...
What is application domain? Explain. An application domain is the CLR equivalent of an operation sys...
Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?...
How To Select an Oracle System ID (SID)? - Oracle DBA FAQ - Creating New Database Instance Manually ...
What's the difference between J2SDK 1.5 and J2SDK 5.0? There is no difference, Sun Microsystems just...