|
why u used fscanf..? why fgets not..
fscanf returns when white space is encountered.
so you can use fgets which reads the file line by line.
Thanks and Regards
Laxman
FAILURE is the first step towards SUCCESS 
|
|
|
|
|
Laxman9 wrote: fscanf returns when white space is encountered.
Not exclusively.
Laxman9 wrote: so you can use fgets which reads the file line by line.
fscanf() can also do this.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
fscanf function reads a word from file. This is why you do not get any space.
If you want to get space then use another function instead of fscanf.
MANISH RASTOGI
|
|
|
|
|
it seems that you're using either c and C++ functions.
i suggest you using the standard STL library, with std::iostream and std::fstream .
there, you'll dispose of a getline() function whichcan be configured to read until a \n character (by default) of whatever other...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Ok There are lots of good suggestions.
I thought to give the answer in your style only.
fscanf(f, "%[^\n], temp1);
this will read string of character until it will get a new line;
I just add as one of the answers. But the previous answers are more perfect.
|
|
|
|
|
While you may get it to work, your code is not very efficient as it reads from the disk way too often. If all you are doing is reading from a file and displaying the contents in an edit control (i.e., you wanted words and spaces), I suggest something like:
CFile file("c:\\log.txt", CFile::modeRead);
LPBYTE lpBuffer = new BYTE[file.GetLength() + 1];
UINT uBytesRead = file.Read(lpBuffer, file.GetLength());
lpBuffer[uBytesRead] = '\0';
file.Close();
m_Text.SetWindowText(lpBuffer);
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
I have some doubts with regards using the above method.
Now the data may need to b displayed on Editcontrol whih is on a different dlg than the one from which the read request has been initiated. So one needs to store the data on2 a CString or like to Xfer the data to dat dlg.
Secondly, when u read file data u wud not know in advance how large the file length wud b, so allocation of a very large buffer wud not b advisable. How abt having a fixed size buffer that reads data and does
CFile FileToRead;
FileToRead.Open(<filepath>);
DWORD dwBytesRemaining = FileToRead.GetLength();
while(dwBytesRemaining)
{
UINT nBytesRead = FileToRead.Read( buffer, sizeof(buffer) );
CString += buffer;
dwBytesRemaining -= nBytesRead;
}; ??
CString wud manage the hassles of mem mgmt and u have read all the data w/o any allocation work by urself. Does CString have any limitations of not being able 2 store large data or newline probs etc??
|
|
|
|
|
cpp_prgmer wrote: Now the data may need to b displayed on Editcontrol whih is on a different dlg than the one from which the read request has been initiated.
It makes no difference, as long as the data being read is accessible by the other dialog.
cpp_prgmer wrote: So one needs to store the data on2 a CString or like to Xfer the data to dat dlg.
The example I provided did store the data in a BYTE variable.
cpp_prgmer wrote: Secondly, when u read file data u wud not know in advance how large the file length wud b...
Sure you would. I also showed this in the example. Did you not see it? Strangly enough, you used the same CString::GetLength() call in your code snippet.
cpp_prgmer wrote: How abt having a fixed size buffer that reads data and does...
Like I previously indicated, multiple disk reads are not necessary, and can be detrimental to performance.
cpp_prgmer wrote: CString wud manage the hassles of mem mgmt and u have read all the data w/o any allocation work by urself.
Yes, CString does this, but how much trouble is it to use the new operator once with the tradeoff being less disk I/O? Furthermore, the CString += buffer statement can be a lot more expensive than a single use of the new operator.
cpp_prgmer wrote: Does CString have any limitations of not being able 2 store large data or newline probs etc??
No.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
hi~everyone
i hava a question puzzle me ! when i used "CreateDirectory" function make a file use unicode in windows 98
but it's allways fail !
please help me ande very thanks in advance!!
nothing
|
|
|
|
|
as far as i know, unicode support in win98 is not too good and unicode apis are not well documented.
-Prakash
|
|
|
|
|
You need MLU[^] to work with Unicode in 98 Machine :->.
Regards,
Aljechin Alexander.
|
|
|
|
|
ebinaini wrote: ...but it's allways fail !
What does GetLastError() return?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
HI,
I use this code to creat a windown. I want to know there way to make sure it is always on the top of the other windows of others application. Can I anyone send me a pointer?
// Create a main window for this application instance.
hWnd = CreateWindow(
"SWClass",
"M App.",
WS_OVERLAPPEDWINDOW, // Window style.
1000, // Default horizontal position.
000, // Default vertical position.
280, // Default width.
100, // Default height.
NULL, // Overlapped windows have no parent.
NULL, // Use the window class menu.
g_hInst, // This instance owns this window.
NULL // Pointer not needed.
);
Jim
-- modified at 19:40 Tuesday 24th January, 2006
|
|
|
|
|
Use the SetWindowPos API function on your hWnd.
Take a look in MSDN about how to use it. Or maybe this is enough, I took it for you:
BOOL SetWindowPos( HWND hWnd,
HWND hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
UINT uFlags
);
Put hWndInsertAfter = "HWND_TOPMOST" and then at uFlags SWP_NOMOVE and SWP_NOSIZE and SWP_NOACTIVATE, depending on what exactly you wish to do. More details about all those in MSDN :- D.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Axonn Echysttas,
Thank you so much for a quick reply. Another quick question, if I want to dock my window in the top-right conner of the screen, what enum should i use? Sorry for my novie quesiton since i am kind of new to this windows programing thing.
Thank again.
Jimmy
Jim
|
|
|
|
|
You can't dock it there. You must use some dynamic positioning. It's easy. Grab screen dimensions using GetSystemMetrics(SM_CXSCREEN) and GetSystemMetrics(SM_CYSCREEN). Those will return X/Y sizes in pixels. Then make some simple arithmetic calculations to determine where your window's X should be so that it's X + WIDTH reach the screen total X : ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
hi there,
Work like a charm...thank a bunch!!!!!!!!!!!
Jim
Jim
|
|
|
|
|
You're most welcomed : ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Hi, all,
Let's say math is not my strong subject.
That said, can anyone explain to me how to pack a floating point value into a 4 byte char array?
Any help would be much appreciated.
Thanks in advance.
|
|
|
|
|
You should use a union.
union FloatConverter
{
float fValue;
char Bytes[4];
};
|
|
|
|
|
Thanks for the info.
What I was actually looking for is something along the lines of char bytes[4] = float.
or possibly send it to a memory file and read back into a character array. I just have no clue as to how it should be done.
|
|
|
|
|
P1P3R wrote: What I was actually looking for is something along the lines of char bytes[4] = float.
A union will do this. It's actually quite simple. Each member in the union occupies the same memory space. So anything you put into the float will show up in the char array. Anything you put into the char array will effect the float.
union FloatConverter
{
float fValue;
char Bytes[4];
};
void Test()
{
FloatConverter converter;
converter.fValue = 1.23;
char floatByte0 = converter.Bytes[0];
char floatByte1 = converter.Bytes[1];
char floatByte2 = converter.Bytes[2];
char floatByte3 = converter.Bytes[3];
}
|
|
|
|
|
I did not know this. Will give it try.
many thanks.
|
|
|
|
|
Hm... I got a weird weird problem. I subclassed the Systray Clock window but the WM_LBUTTONDOWN message ain't comming through my window procedure, the one I subclassed it to. This is really something 'cause subclassing is meant to direct ALL messages to me, but that message simply ... doesn't get here. What could be wrong?? I receive other messages as WM_PAINT and the subclassing is perfect since I already use it for other purposes.
Could this be a hint?
SetClassLong(pcwps->hwnd, GCL_STYLE, GetClassLong(hwndSystrayClockWindow, GCL_STYLE) & ~CS_DBLCLKS)
What does "& ~" do anyway? I haven't been programming in C++ for such a long time and I am unfamiliar with that construction. Is it meant to subtract an attribute from that window's Class Bits?
Pffff... weird stuff goin' on here... ::- |.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
Hi,
the "& ~" construction means to remove the class style CS_DBLCLKS from the window. But this isn't necessarily the source of your problem. MSDN says the following:
>> If a window does not have the CS_DBLCLKS style, Windows sends
the following message sequence to the window: WM_LBUTTONDOWN,
WM_LBUTTONUP, WM_LBUTTONDOWN, and WM_LBUTTONUP.
>> If a window does have the CS_DBLCLKS style, Windows sends the
following message sequence: WM_LBUTTONDOWN, WM_LBUTTONUP,
WM_LBUTTONDBLCLK, and WM_LBUTTONUP. That is, the second
WM_LBUTTONDOWN message is replaced by a WM_LBUTTONDBLCLK
message.
So I guess the problem is located somewhere else.
regards,
mykel
If they give you lined paper, write the other way!
|
|
|
|