Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Request help -- odd sprintf, fprintf issue |
| Date | 2016-08-29 10:48 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <nq10do$dpf$1@dont-email.me> (permalink) |
| References | <e9765d0c-e510-41ee-9b72-02a85734d45d@googlegroups.com> |
On 29/08/2016 07:58, dakupoto@gmail.com wrote: > Could some C language guru please help ? > I am using gcc on Fedora 18. > > I have a simple function to write formatted > character strings to a text file, the snippet > that is causing problem is: > > memset(b, 0, SLEN); > sprintf(b, "%s%s%d%s%d%s%f%s", > "RS"," ",snode," ",enode," ",ld,"\n"); > fprintf(a, "%s", b); > memset(b, 0, SLEN); > > Here, 'a' is the non-NULL pointer to a text file, > 'b' is character array of size 32, and enode and > snode are integers as 1, 2, ... > > The output looks is(for one particular run): > > S 1 2 50.00 > > I do not understand what is causing the 'R' in > 'RS' to not get printed What happens if you replace the fprintf with printf? What if, just before the above code, you write: fprintf(a,"<"); Do you get "<S 1 2 50.00" or "<RS 1 2 50.0"? (Or "RS 1 2 50.0" and it's the "<" that's missing.) What is the return value of sprintf? (It should be the number of characters printed, which I think is 13 if "\n" is counted as one.) Since the output is to a file, what do you use to look at the file? Do you get the same result if you look at a dump of the file? (As the "R" might somehow hidden or overwritten.) -- Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Request help -- odd sprintf, fprintf issue dakupoto@gmail.com - 2016-08-28 23:58 -0700
Re: Request help -- odd sprintf, fprintf issue gazelle@shell.xmission.com (Kenny McCormack) - 2016-08-29 08:09 +0000
Re: Request help -- odd sprintf, fprintf issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-29 10:30 +0100
Re: Request help -- odd sprintf, fprintf issue BartC <bc@freeuk.com> - 2016-08-29 10:48 +0100
Re: Request help -- odd sprintf, fprintf issue Brett Dong <brett.browning.dong@gmail.com> - 2016-08-29 18:15 +0800
Re: Request help -- odd sprintf, fprintf issue Dutch Ingraham <spikeheron@att.net> - 2016-08-29 08:21 -0500
Re: Request help -- odd sprintf, fprintf issue Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2016-08-29 09:10 -0600
Re: Request help -- odd sprintf, fprintf issue Keith Thompson <kst-u@mib.org> - 2016-08-29 10:27 -0700
Re: Request help -- odd sprintf, fprintf issue Ike Naar <ike@iceland.freeshell.org> - 2016-08-29 19:51 +0000
Re: Request help -- odd sprintf, fprintf issue Keith Thompson <kst-u@mib.org> - 2016-08-29 14:30 -0700
Re: Request help -- odd sprintf, fprintf issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-30 10:56 +0100
csiph-web