|
You're right about the len in the printed string - my turn to not think clearly about what he's doing!
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
I understand the point, but maybe it would be nice to avoid both continuos allocation/deallocation of memory and use of the log10 . Simply allocate once a (relatively) big buffer on the stack.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Well, perhaps that would be ok, but if the file size is large (2 GB) the new of a 2GB char array would probably fail, and you don't need anywhere near that many characters to hold a file size.
Perhaps a fixed buffer size of say [MAX_PATH_LEN] (which is 256) would be more than enough characters to hold any file size.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
krmed wrote: Well, perhaps that would be ok, but if the file size is large (2 GB) the new of a 2GB char array would probably fail, and you don't need anywhere near that many characters to hold a file size.
Of course the buffer can't be sized equal to file dimension, have you missed my aknowledge about your point?
That stated, my post completely agree with your bottom line:
krmed wrote: Perhaps a fixed buffer size of say [MAX_PATH_LEN] (which is 256) would be more than enough characters to hold any file size.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Sorry if you thought I meant that all at you.
Actually, I was agreeing with the fixed size, but wanted the OP to realize that he probably can't new a char array the size of the file length (and it wouldn't be needed anyway).
I was simply suggesting that a fixed size (like you said) would work, and MAX_PATH_LEN would be more than enough - in fact 20 characters will hold more than ever needed.
Have a great day!
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
neha.agarwal27 wrote: char *len_str = new char;
sprintf(len_str,"%d",len);
Since you are using MFC:
CString len_str;
len_str.Format("%d", len);
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
and in addition to DavidCrow's reply...
Since you're using MFC and a CString, which is a generic string type,
use generic literals as well...
CString len_str;
len_str.Format(_T("%d"), len);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can assign your value to control with Set SetDlgItemInt and you dont need to other variables.
|
|
|
|
|
Hi all ,
i am trying to write a text file to a given location like c:\abc.txt
can anybody help me here..
Thanks in adavnce
vikas
|
|
|
|
|
What's the problem. See point 2 here[^]
|
|
|
|
|
i am just trying to write a text file to some specified path... that will contain some string data ....
as an example.. if i have a string "hii i am here in code project"
so this will be written there in the text file (text file will be created from code)
please help out me here
Thanks in advance
vikas
|
|
|
|
|
You can use of CFile class for read and write.
|
|
|
|
|
Thanks Hamid,
i think this is inbuild class but i want to do this by code just like...
1. create a text file
2.Open the file in read/write mode
3.append the text/write the text
4.close the file
thanks alot guys for help
vikas
|
|
|
|
|
tasumisra wrote: i think this is inbuild class
What ?
You can perfectly use CFile in your code, what's the problem ? Just look in MSDN how to use the class.
|
|
|
|
|
i dont want to use
class CFile : public CObject
BECAUSE
i am writing a COM component in that i need to put some log
so there i cant use CFILE may be it can be used there but i dont know..
so please help me in this context
Thanks...
vikas
|
|
|
|
|
Use a std::ofstream instead.
#include <fstream><br />
using namespace std;<br />
<br />
...<br />
...<br />
<br />
<br />
ofstream MyFile("Output.txt");<br />
MyFile << "Hello World" << endl;
|
|
|
|
|
Thanks for your help i ll check it..
vikas
|
|
|
|
|
use these win32 API's CreateFile,WriteFile
dlfkgj lsdfkglfkgjlfgl jldfk fldkk jk
|
|
|
|
|
tasumisra wrote: i am writing a COM component...
Which is an advanced topic. If writing to a text file is troubling you, COM will be next to impossible.
tasumisra wrote: ...may be it can be used there...
Certainly it can, but that's irrelevant at this point.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: COM will be next to impossible
NO BODY is there who knows COM BY BIRTH .... here only everybody had learnt and me too... will prove it...
vikas
|
|
|
|
|
tasumisra wrote: will prove it...
Good luck.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
What about FILE and fopen ?
|
|
|
|
|
hi
i am developing a application in server and client on MFC.
when i execute server and client ,Buffer over run error occur in client side .
it will be greatful if i get answer
k.guru moorthy
|
|
|
|
|
guru moorthy.k wrote: it will be greatful if i get answer
Hence try to post a question.
BTW:
guru moorthy.k wrote: i am developing a application in server and client on MFC.
when i execute server and client ,Buffer over run error occur in client side .
The above scenario is too broad to get any help (at least from me ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
guru moorthy.k wrote: it will be greatful if i get answer
The answer is: don't overrun the buffer. Problem solved.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|