|
I would read the file by mapping it into memory[^], not reading it using file I/O functions. That allows me to treat the file as a continuous block of memory, so searching the file for a string is almost as as simple as using strstr[^] - I actually used this code to search backwards through a file (specified as the first argument on the command line:
int main(int argc, char* argv[])
{
DefaultFileReader fr(argv[1]);
const char* lookBegin = argv[2];
const size_t lookLen = strlen(argv[2]);
const char* lookEnd = argv[2] + lookLen;
const char* p = (const char*)fr.end()-lookLen;
while (p!=(const char*)fr.begin())
{
if (!strncmp(lookBegin, p, lookLen)) break;
--p;
}
size_t firstPos = p - (const char*)fr.begin();
std::cout << firstPos << std::endl;
return 0;
}
DefaultFileReader is a class I've written that memory-maps a file. It has begin() and end() methods to access the memory that has been mapped.
You can see that my code isn't looking for lines in the file - that's not really necessary once you know what text you're looking for (but could be added - line terminators are just characters!).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Rajesh_Parameswaran wrote: WinExec("findstr /C:\"ERROR #1028\" C:\\SERVER.log > C:\\temp_log.txt", SW_HIDE)
But, the output seems to be not re-directing to the temp_log.txt file.
I even tried creating the file temp.txt before executing the same, but the contents will be blank. Even I tried the >> operator too.
This all has to do with > and >> not being passed on to the command processor. As you've noted, if you want to do it this way, you'll need to write that string to a BAT file and WinExec() that instead.
How is the file formatted? Is it in any order? How often is the file updated?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi David,
This log file is plain text file, a Sybase generated one for replication server and the logging will be very frequent and dynamic.
Sample content of the file listed below:
==================================================================================
I. 2006/03/15 06:50:48. The first transaction for database 'JAGUAR1.blue' has been logged into the exceptions log and skipped.
I. 2006/03/15 06:50:49. A grouped transaction of 2 individual transactions has failed in database 'JAGUAR1.blue'. Each transaction in the group will be executed individually.
E. 2006/03/15 06:50:51. ERROR #1028 DSI EXEC(104(1) JAGUAR1.blue) - dsiqmint.c(3062)
Message from server: Message: 2601, State 1, Severity 14 -- 'Attempt to insert duplicate key row in object 'NIiAppStat' with unique index 'XPKNIiAppStat'
'.
I. 2006/03/15 06:50:51. Message from server: Message: 3621, State 0, Severity 10 -- 'Command has been aborted.
'.
H. 2006/03/15 06:50:51. THREAD FATAL ERROR #5049 DSI EXEC(104(1) JAGUAR1.blue) - dsiqmint.c(3069)
The DSI thread for database 'JAGUAR1.blue' is being shutdown. DSI received data server error #2601 which is mapped to STOP_REPLICATION. See logged data server errors for more information. The data server error was caused by output command #1 mapped from input command #2 of the failed transaction.
I. 2006/03/15 06:50:51. The DSI thread for database 'JAGUAR1.blue' is shutdown.
==============================================================================
I'm looking for time stamp for "ERROR #1028 DSI EXEC(104(1)"
Thanks in Advance,
Rajesh
|
|
|
|
|
I want to Create a logical(not physical)Bad sectors on hard disks!
Is it possible?
If possible what i should know?
----------------------------------------------
I think
A fabricated ECC could be a solution
Originally ECC is made by automatically...
I cannot get a specific answer to insert ECC artificially.
Let`s consider it together...
Thanks Advance.
modified on Thursday, June 25, 2009 1:19 AM
|
|
|
|
|
It is possible for me to say no dont say 'why'?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I built kernel with C6. minigui.org see I do not understand.
Who helped write the example minigui and OS kernel dev thanks
by:tuan1111
|
|
|
|
|
tuan1111 wrote: I built kernel with C6. minigui.org see I do not understand.
Who helped write the example minigui and OS kernel dev thanks
Honnestly, I don't think it is very useful to continue posting on this forum unless you improve your english a bit. All your posts were totally undecipherable (at least for me). So, why do you continue posting questions that you alone understand ?
|
|
|
|
|
My Vietnam
I write kernel os.Lam stars using VC6 write kernel and load it.
How to create _asm graphics.h for this kernel and use it in Vc6
by:tuan1111
|
|
|
|
|
Could you please make a more clear request?
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello,
I have one problem with two different projects created in VS2003 and VS2005.
First of all I have a MFC extension dll in one project created in VS 2005. When we load this dll through test project created in VS 2005, everything is fine.
Now we need to use this same dll in one of the application created earlier using VS2003. In this application there is one mediator dll which I have compiled in VS 2005 and connected the previous MFC dll to this app.
After this if I do only
LoadLibrary(...) and
FreeLibray(..) immediately;
the VS2005 shows memory leaks in MFC dll before it unloads it.
What should I do?
Can program Money?
|
|
|
|
|
Dynamic linking mixed versions of MFC is an iffy proposition at best.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Very right. I came out of iffy position after I made few changes and compiled the complete application projects in 2003 and then linked them to existing 2003 app. Believe it everything is correct and I have the project ready.
Can program Money?
|
|
|
|
|
Hello
Can anyone tell me like the things to be taken care of, while moving to UNICODE format, because the application am working is going to be supported in multiple languages?
while using functions like strcpy_s, do i need to be more specific about the size_t parameter?
that is, while doing a copy, do i need to specifiy more memory?
Thanks in advance.
|
|
|
|
|
Use the tchar equivalents of the str* functions, and wrap your string constants in the _T macro. As for the size_t parameter you can leave it as is as they refer to the number of characters in the buffer, not the number of bytes. As was said earlier, RTM.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
To add to the above; go to the documentation for the string calls. Scroll down. The remarks section will contain a list of what the equivalent tchar routine to use that will map to either the ANSI or UNICODE version of functions. So, the equivalent of strcpy_s is _tcscpy_s.
The second parameter of strcpy_s is the number of characters in the destination buffer. If you have a static buffer (i.e. TCHAR buffer[16] ) and are using sizeof(buffer) , you'll have to modify it to use sizeof(buffer) / sizeof(TCHAR) (in VS 2005 you can, as was already clearly pointed out below, use _countof(buffer) .)
dipuks wrote: that is, while doing a copy, do i need to specifiy more memory?
It depends on how you are allocating that memory. If you use TCHAR when allocating, then you're fine.
BTW, if using the defines LPCSTR & LPSTR, change them to LPCTSTR & LPTSTR. Most of these will be flagged when you compile with UNICODE.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
modified on Wednesday, June 24, 2009 11:53 PM
|
|
|
|
|
I learned MFC before, finally I gave up completely.
then now much more easier way than MFC exists, then I really do not understand why MFC
is still used? what is the advantage then?, let us say, compared to .net. Mainly due to its efficiency? but my experience told me that it is really not make progress in MFC.
thanks
modified on Wednesday, June 24, 2009 4:47 PM
|
|
|
|
|
1) There are still places where the .NET framework isn't widely installed, so .NET apps aren't an option (I know, I work at one)
2) I would say that MFC still has a better developed application framework than (say) Windows Forms - things like UI updating just seem better in MFC, IMO.
If you're going to use something instead of MFC, use Qt - that's a really nice UI framework, IMO - or (maybe) WTL - MFC-esque but lighter weight and (IMO) some things are nicer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
MFC has a more complete application framework. For example, the menu handling and tying menu items to button bar buttons.
Once you understand MFC and Visual Studio, it is very easy to rapidly create applications.
MFC has a massively huge amount of third party resources for it. CodeJock, for example, is an excellent UI interface (far better, IMO, than the BCG stuff Microsoft used for the 2008 Feature Pack.)
With few exceptions, MFC lets you seamlessly move between native Win32 and the framework.
MFC/Native applications [can] use much less memory than .NET applications.
MFC did languish for several years, then Microsoft did some actual research of actual developers and found that as of 2003/2004, 80% of client application developers world wide was still using MFC. As a result, they are paying attention again and for 2010 are allegedly adding back the fabulous Class Wizard from Visual C++ 6 and before. As for efficiencies; due largely to the heavy amount of COM added, it's become more bloated, but it's hard to make it much more efficient without changing the design (and even then, for large applications, the difference would be negligible.)
At one point WTL showed promise, but it was rather confusing and time consuming to create window classes. Unfortunately, rather than add some Wizards and beef up support, Microsoft threw WTL into the public domain. (Shame since I have shipping applets which could have been main leaner with WTL.)
Many (please note that I didn't say all) developers I personally know who claim .NET is superior to MFC were never very good at MFC; they never bothered to really learn it or Win32. Most of those are just as bad at .NET too; they just think they aren't. I use native Win32, MFC, and .NET. Many things are easier in .NET, some things are harder and some things are so blasted hard, it's just not worth it. There are some really nice things about .NET and C#, but when all is said and done, I'm a C/C++ programmer at heart. (Having said all that; anyone who needs to do web development or pure database front ends would be crazy to pick C++ over .NET.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
May i know how can i create a Slider Control with three ranges...ie
1--------2---------3
based on the movement ie if the slider is at 1 i need to display a static text as low(and need to set some registry also)and if 2 it should display medium AND 3 as high..
Please let me know regarding the same...
|
|
|
|
|
So what exactly is the problem? Have you called the SetRange(1, 3, TRUE) method, or sent the control a TBM_SETRANGE message?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello all,
I am having problems with opening a device defined serial port using basic CreateFile function. The serial port is specific to a framegrabber installed in the PC. I can open and communicate with it with no problems in windows hyper terminal and evne in Matlab, but not able to open it in VC++. Usually with other framegrabber I can see all the additional com ports installed by the framgrabber under COM&LPT ports in device manager, but not with this board. But in registry under HKLM\HARDWARE\DEVICEMAP\SERIALCOMM, I see these ports listed.
The port names are not as usual COM1 etc, its with X64-CL_iPro_1_Serial_0/X64-CL_iPro_1_Serial_1 names.
Can anyone help me out here.... or does anyone know how windows hyper terminal opens these ports..
thanks,
PKNT
|
|
|
|
|
Hi
I am using something like,
char des[10];
char src[2] = "Hello";
strcpy(des, sizeof(des), src);
Because this application is going to be internationalized, i want WCHAR or UNICODE format implemented.
So will that make any change to calling sizeof(des)?
Do i need to do soemthing like, sizeof(des) * sizeof(char) ??
|
|
|
|
|
wchar_t buf1[80], buf2[80];
wcscpy_s(buf1, _countof(buf1), buf2);
You might want to read the documentation[^]
|
|
|
|
|
led mike wrote: You might want to read the documentation[^]
That's optional, isn't that?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Of course! Many developers just wave their magic wand keyboard at the problem.
|
|
|
|