|
Hi All.
I have difficulty to save the content of variable (e.g. 2 dimension array) to a txt file using visual c++ 6.0 MFC.
Sample case :
double pic[4][4]={0,1,0,1, 1,0,1,0, 0,0,0,0, 1,1,1,1};
and I want to save it to the txt file (e.g. myFile.txt) so that myFile.txt contains 0,1,0,1, 1,0,1,0, 0,0,0,0, 1,1,1,1 which is readable (non-binary format) when I open the file with notepad.
Can anyone help me to solve this problem ?
Thanks very much for your attention and help in advance
Regards
Ronald Ruly
University student in Singapore
|
|
|
|
|
I suppose you should use itoa() on your data (items in your array) and then simply write it down as a string.
---
http://sprdsoft.cmar-net.org - We Sprd You Softly
Our site features contents and several images. All of this is very weird.
In the end, war is not about who's right, it's about who's left.
|
|
|
|
|
Thanks Titan for your attention.
I have got the answer from my friend. The solution that I got from my friend is like this :
FILE *file=fopen("myfile.txt","w");
if (file != NULL)
{
fprintf(file,"scale:%d max:%d\n",6,4);
for(m=0;m<256;m++)
fprintf(file,"%d ",histogram[m]);
fclose(file);
}
I didn't know before that variable type FILE can be used for MFC, because I had always been overwhelmed by CFile that deals with the binary file IO.
Regards
Ronald Ruly
University student in Singapore
|
|
|
|
|
Hello,
I've write a little programm to get data from a server using CAsynSocket.
All is ok but when the server send :
1rt trame : HELLO1.HELLO2\n.
2nd trame : HELLO3\n.
3rt trame : HELLO4. (where '.' is a null byte)
I've got only :
1st call to Receive() : HELLO1
2nd call ............ : HELLO3
3st call ............ : HELLO4
So the socket do not cath the HELLO2.
I am using CommView to see the trame and sometimes this happen so I do not all the data
If someone can help me to understand what is wrong.. thanks in adavance.
Part of my code to get data :
void CMySocket::OnReceive(int nErrorCode)
{
char buf[4096];
int nRead;
nRead = Receive (buf,4096); // Receive data
....
}
-- modified at 9:16 Saturday 17th December, 2005
|
|
|
|
|
Hello.
I think the problem isn't in the socket handling, it's a display problem.
The "\0" (null) is a string terminator, so that's the reason why you just see "HELLO1".
|
|
|
|
|
#include <afxwin.h><br />
#include <typeinfo.h><br />
#include <iostream><br />
using namespace std;<br />
<br />
class CAge: public CObject<br />
{<br />
public:
int m_age;<br />
public:<br />
CAge(int paraAge)<br />
{<br />
m_age = paraAge;<br />
}<br />
~CAge(){}<br />
public:<br />
virtual void AssertValid() const;<br />
};<br />
<br />
int main()<br />
{<br />
CAge* pcage = new CAge( 21 );
ASSERT( pcage!= NULL );<br />
ASSERT( pcage->IsKindOf( RUNTIME_CLASS( CObject ) ) );<br />
<br />
cin.get();<br />
return 0;<br />
}<br />
<br />
<br />
shanzy<br />
<br />
-- modified at 9:01 Saturday 17th December, 2005
And the compiler tell me:
error LNK2001: unresolved external symbol "public: virtual void __thiscall CAge::AssertValid(void)const " (?AssertValid@CAge@@UBEXXZ)
fatal error LNK1120: 1 unresolved externals
|
|
|
|
|
|
Thank you for your tip,I forget to implement it,
shanzy
|
|
|
|
|
hi
i create 2 window in the SDI document using splitter..I need scroll bars ..But it's not happen..how can i add scroll bars..if i using CScrollBar
it's not working
sid
|
|
|
|
|
|
Whenever i debug a dll thru the main application the execution is not coming to the break point inside the dll and whenever i press shift+F5 it is showing "Preloaded symbols may not match <mydllname>.dll."
Please tell me what is happening.
Thanks in advance,
John
|
|
|
|
|
In your debug settings, under Additional DLLs, did you happen to add the DLL so that you may set breakpoints in it before running the application? If so, you may have provided the wrong DLL path.
This can happen if you specify a Debug configuration path (e.g. "C:\...\Debug\MyDLL.dll") whereas the application loads the Release configuration of the same DLL (e.g. from "C:\...\Release\MyDLL.dll"). Although the two DLLs have the same name, they are loaded as separate modules into memory. The breakpoints are set in the module that never gets a chance to run.
This can also happen if your DLL is a COM server (e.g. implements an ActiveX control). Whether the Release or Debug version of the DLL gets loaded depends on the last settings made in the registry. You need to lookup the CLSID of the implemented ActiveX control (HKEY_LOCAL_MACHINE\SOFTWARE\CLSID\yourclsid) and see what InProcServer DLL is registered - the release or debug version. Then, in your application's debug settings, you need to synchronize the specified DLL path to this.
Hope this helps.
|
|
|
|
|
hey guys,i have been working on a little demo ftp program,where the server has read data into a buffer and is sending it to the client which inturn will write the file to a directory on the local drive,but im wondering what the best way to send the data is? if i was sending a lage file would i be able to send the data in one whole chunk? or is there only so much data a winsock send function can handle at any one time,would the data have to be sent seperatly in chunks and then put back together at the other end? any brief information would be great. thanks chris
|
|
|
|
|
Dear Mr;
I need some help to solve this programming question if you please the question said:
If we have a file of record (i.e. student.Dat)
Given the following record structure,
St_ Rec = record
St_ no : longint ; { primary key }
St_ name : string [50]; {secondary key 1}
Ma-jor : string [2]; {secondary key 2}
Year : byte; {secondary key 3}
Address : sting [50];
End
Write a c++ program that
2) Allows the user do the following
a) Add and delete a record dynamically (Using the avail list)
b) Modify the information in any given record
c) Query the data file using single key or combination of two secondary keys (and / or)
d) Display the contents of the file page by page in table format
Note 1:- use menu to allow the user to choose the required operation.
Note 2:- use canonical form for names
losan1985
|
|
|
|
|
losan wrote: I need some help to solve this programming question if you please the question said:
Have you coded something dear
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
|
hi ,
this is about memory/speed size optim.
take this for example:
const int cAIMessageRouter_Init_ReserveRegisteredObjectCount = 64;
const int cAIMessageRouter_Init_ReserveDelayedMessagesCount = 16;
if i replace the int with a char or short.... what would be better....
Size does matter becouse every BIT send to the server ..........
How smaller the player data, how faster the server can respond.
But i dont know this: is const char value=12;
FASTER then
const short value=12;
const int value=12;
or slower?
|
|
|
|
|
Try it out yourself by using sizeof and passing each of those items. example:
cout << "Size of an integer: " << sizeof(int) << endl;
|
|
|
|
|
if i do sizeof(int) i get 32 or 16.
With a char i get 8
But if i use a char to hold a integer value of 5, wouldn`t that be slower?
becouse chars are mainly used for strings.
|
|
|
|
|
Characters are represented by a numeric value. It is that value that is stored in your variable not the letter itself, for chars these are the ASCII values. So its just as fast to use a number as it is to use a letter.
|
|
|
|
|
Thanx.
The game (soldner secret wars) i am working on (mainly patches) has many data like:
const int max_sounds=5;
by using this:
const char max_sounds=5;
i can optimize SIZE, becouse 20 classes uses 1 class for work that has this defined.
or am i wrong?
cu
|
|
|
|
|
oversight-[project-zero] wrote: chars are mainly used for strings.
Not exactly true. Char's are used for lots of things, including pure data manipulation. It's simply 2 bytes which can be interpreted as an ANSII character. That said, if you're only going to be holding very small numbers like 5 and you're EXTREMELY worried about space/efficiency, you should use BYTE for values which you know will be less than 16. I'm not sure how much time this will all save you to be honest, these types of issues are normally only a passing thought in designing your application because there are so many more design issues that would likely speed up your program much more.
|
|
|
|
|
thanx,
at this moment we have still (mod-team) status... and i am the only c/c++ coder.
This forum is a great help.
(talks are going on about soldner 2 www.secretwars.net= www.soldner.jowood.com)
You might wonder why this game source is so complicated lol.
(i hate wings !!!, crappy coders!!!!)
i can use a few helping hands making soldner a better game, if you are interested.....
The source is like this:
dynamics,core etc is defined in classes, DEEP polymorpish and derived stuff.
(just defined..... no value`s in c++)
The xml and python is used to define the game property`s.
Thats called the gdb::xxxxx (game database).
The gdb is implemented in c/c++ but called from python and xml.
becouse of this complexity, i am seeking for talented coders.
At our team talks are going on about a contract with jowood.
We where/are a mod team, but i think thats changing rapidly.
Jowood needs project zero, without project zero NO soldner.
Cu at the soldner battlefield.
|
|
|
|
|
|
oversight-[project-zero] wrote: becouse chars are mainly used for strings.
what's that crap ?
char is an integer in C/C++, and its name is quite bad as beginners make too much confusion... a char is only a 8 bits integer. in C/C++, there's no high level type for strings. strings are simply char arrays, ended with a char whose value is 0 .
never using a char will slow down your application compared to an int for such a use...
however, you'll have to consider the values stored within... char is a signed type, so stored values between -128 and 127 . if you want values from 0 to 255 , use unsigned char . and if you want more, use short , int (size is dependant of the plateform ; can be 8, 12, 32 or 64 bits !!! be careful !), long ...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|