Mail Archives: djgpp/2000/02/09/23:47:14
From: | "Paul Bibbings" <paul DOT bibbings AT tesco DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: sprintf woes
|
Date: | Thu, 10 Feb 2000 03:26:03 -0000
|
Organization: | Tesco ISP
|
Lines: | 55
|
Message-ID: | <87tbs3$ftl$1@epos.tesco.net>
|
References: | <87pssv$12f$1 AT nnrp1 DOT deja DOT com>
|
NNTP-Posting-Host: | 212.140.69.164
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.00.2014.211
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2014.211
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
The problem with your program is that you declare the pointers *f, *g, etc.,
but you don't associate any memory with these in which to store your
strings, and note that you need enough space to include the strings
themselves plus a terminating NULL character.
Hence, for char *f use char f[2], and for char *j use j[7], etc. Your
program will then work properly. (See below).
<mrdang AT my-deja DOT com> wrote in message news:87pssv$12f$1 AT nnrp1 DOT deja DOT com...
> I am having a lot of trouble with sprintf. I can not seem to make it
> do what I want within a subroutine / procedure. As an example:
****************************************************************************
#include <stdio.h>
void testing(void);
int main()
{
char f[2], g[2], j[7];
testing();
testing();
sprintf(f, "q");
sprintf(g, "w");
printf("%s\n", f);
printf("%s\n", g);
sprintf(j, "s: %s %s", f, g);
printf("%s\n\n", j);
return 0;
}
void testing()
{
char t[7], m[2], h[2];
sprintf(m, "b");
sprintf(h, "d");
printf("%s\n", m);
printf("%s\n", h);
sprintf(t, "s: %s %s", m, h);
printf("%s\n\n", t);
}
- Raw text -