|
From: Per W. <pw...@ia...> - 2003-07-03 17:15:32
|
But that ignores the problem that sizeof(temp) doesn't take into account
the number of characters in the buffer, only total declared size of it. As
such, sizeof(temp) should never be used for emitting text files unless you
really, really, really - did I say really? - know what you are doing.
strlen() is available specifically for checking the length of a string.
In the first WriteFile() call, temp contains 2 characters, a terminating
zero and an unknown number of extra garbage at the end - depending on what
size it was declared as.
In the second WriteFile() call, temp constans 3 characters, a terminating
zero and an unknown number of extra garbage.
Besides, sprintf(temp,"\r\n","") is a bit expensive since the formatting
string didn't contain any formatting. That is when strcpy(temp,"\r\n")
should be used.
Further, since the emitted string is a constant, why not directly emit
WriteFile(hFile,"\r\n",2,&dWritten,NULL);
Any why not check the return value and the value of dWritten? And - just
a bit more knit-picking - dWritten should be called dwWritten since it is
of type double-word.
/Per W
On Thu, 3 Jul 2003, Daniel Glenfield wrote:
> Hey you guys hear that? I was correct!!! Ha ha! This feels great!
>
> Cheers,
> Daniel
>
> >From: "Jorge Abramian" <jab...@ma...>
> >Reply-To: <jab...@ma...>
> >To: <dev...@li...>
> >Subject: [Dev-C++] (no subject)
> >Date: Thu, 3 Jul 2003 09:47:14 -0400
> >
> >Hey guys, thanks for the help,
> >
> >Actually Daniel Glenfield was write. I did not try Per W. solution that
> >probably would work either.
> >
> >I changed the code to the followin and it worked well:
> >
> >/////////
> > for (loop=0;loop<Number_of_Points;loop++)
> > {
> > DWORD dWritten;
> > sprintf (temp,"\r\n","");
> > WriteFile(hFile, temp, sizeof(temp),&dWritten, NULL);
> > sprintf (temp,"%3d",ran1[loop]);
> > WriteFile(hFile, temp, sizeof(temp),&dWritten, NULL);
> > }
> >/////////
> >
> >
> >
> >
> >-------------------------------------------------------
> >This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> >Data Reports, E-commerce, Portals, and Forums are available now.
> >Download today and enter to win an XBOX or Visual Studio .NET.
> >http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
> _________________________________________________________________
> Sign-up for a FREE BT Broadband connection today!
> http://www.msn.co.uk/specials/btbroadband
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|