From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1103af,c1db52110ef2b04a X-Google-Attributes: gid1103af,public X-Google-Thread: 111c93,c1db52110ef2b04a X-Google-Attributes: gid111c93,public From: U.V. Ravindra Subject: Re: sprintf bug? Date: 2000/05/26 Message-ID: <8gmp47$p5t$1@nnrp1.deja.com>#1/1 X-Deja-AN: 627728627 References: <8gmhrd$jqj$1@nnrp1.deja.com> <8gmilh$kcj$1@nnrp1.deja.com> X-Http-Proxy: 1.0 x54.deja.com:80 (Squid/1.1.22) for client 192.147.112.2 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Fri May 26 21:08:34 2000 GMT X-MyDeja-Info: XMYDJUIDu_v_ravindra Newsgroups: comp.os.linux.alpha,comp.os.linux.misc X-Http-User-Agent: Mozilla/4.73 [en] (X11; U; SunOS 5.7 sun4u) Andreas Kahari wrote: > U.V. Ravindra wrote: > > > > I'm using SuSE 6.3 (Kernel 2.2.13 glibc 2.1.2) on an Alpha EV67. > > > > char buffr[4096+1] > > > > ... > > ... > > printf("before %s\n", buffr); > > sprintf(buffr, "0, 0, 0, "); > > printf("after %s\n", buffr); > > > > And I see the output: > > > > before dwki_nr_ibind(100, fname_var, 0, > > after 0, 0, 0,i > > > It seems to me that you're only using 'sprintf' to copy a string into > an array of characters. Why don't you use 'strcpy', 'memcpy', or a > simple loop instead? Actually, in my actual program, the "0, 0, 0, " is being printed from a function call as sprintf(buffr, "%d, %d, %d, ", fx1(), var_1, fx2()); But I have managed to debug the problem to the point where I know what really is happening here. The 'i' is a remainder from the previous contents of the string, which indicates that sprintf isn't putting the \0 where it should. -Ravindra > But I agree, it looks strange... The 'i' should have been '\0' (or > "\0"). > > /A > > -- > # Andreas K�h�ri, . > # All junk e-mail is reported to the > # appropriate authorities, no exceptions. > > Sent via Deja.com http://www.deja.com/ > Before you buy. > Sent via Deja.com http://www.deja.com/ Before you buy.