|
Hi,
I need to parse text files to search some keywords. I split the search process into many different functions (because they search for different contents). So I thought I could open the file just once and then pass the file stream as a function parameter. In debug mode, the app runs, but in release mode it crashes. Can someone explain me why?
Here is a sample of the code:
void F1 (FILE* source)
{
...
}
void F2 (FILE* source)
{
...
}
void main()
{
FILE* source;
source = fopen("myfile.txt","r");
F1(source);
F2(source);
}
|
|
|
|
|
what error does it repport, and what is the code line like ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Nothing is wrong in above code. may be there is any thing wrong in your function that might be reason for failure in release.
anyway,Try to debug the Program,you may yourself find the error.
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
|
Hi friend,
I tried making a program and i got it worked for both release and debug modes
I don't know whats the problem in your code, but for ensurance here is my code and you can compare:
<br />
#include <stdio.h><br />
<br />
void f1(FILE *f)<br />
{<br />
<br />
while (!feof(f))<br />
{<br />
char s[256];<br />
fgets(s,255,f);<br />
printf("%s",s);<br />
}<br />
}<br />
<br />
<br />
void f2(FILE *f)<br />
{<br />
<br />
while (!feof(f))<br />
{<br />
char s[256];<br />
fgets(s,255,f);<br />
printf("%s",s);<br />
}<br />
}<br />
<br />
main()<br />
{<br />
FILE *file;<br />
file=fopen("c:\\dlls.txt","r");<br />
f1(file);<br />
f2(file);<br />
fcloseall();<br />
}<br />
Here are some advices:
1. may be you should check other parts of your program
2. you should use the object-oriented new C++ classes like ifstream
3. may be if two threads are trying to access the same file simaltanously a failure will occur.
4. you should check the return values from the functions like fopen and others to locate the bug.
I dont know if this helps, but it is all i can do for you friend.
Yours,
Mohammad
a candle looses nothing by lighting another candle
|
|
|
|
|
Ok,
you're right, I'm a dope!
It works. But I discovered that the real problem is in variables declaration.
I'm using fscanf instead of fgets because I need to read a text and analyze each word:
FILE* source;
char* word = new char[512];
fscanf (source,"%s",word)
So, fscanf needs a char* initialised this way, otherwise it won't work. But the pointer initialisation crashes the program.
Any suggestion?
Thanks
|
|
|
|
|
hmmmmmm
your code works on my machine. i feel that there is something wrong,
but i cant figure it out.
but here is a suggestion:
are u sure that scanf places a null-terminating character at the end of the buffer? if it does not, initialize the buffer to zeros.
Thats all i have
my apologises,
Mohammad
|
|
|
|
|
hello,
My MFC application is getting crash because of some message,i don't know which message.Is there any way to track the message which is causing crash?
Thanks.
|
|
|
|
|
you can know the messages sent to your application by running the tracer Spy++ (i think, but not sure), in the debug options of VC++...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
LOng Time NO SEEE
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hello,
I am using a third party vendor's grid in my application.When I create a dynamic combo box on the grid,and drag an item to the grid outside the combo box rectangle,a crash occurs.I hav no idea which message is causing crash.
Any help would be appreciated.
Thanks
|
|
|
|
|
I just updated and re-built a vc6 cpp on a friend's system and moved the dll to another system which does not have the vs dev env loaded. Although it worked great on the "loaded" system (in fact it runs fine as a called dll in a vb.net app) it will not run on another system - I hsve
tried both an old laptop and even a pc at Kinkos
I get a dll load error. I ran the "depends" program
and saw that the dll needed mfc42d.dll (I then realized
that is what I had been missing!). Now I have that loaded apparantly error-free I get a runtime code error, "afxwinl.inl line 22 assert" and then "appui.cpp line 177 assert".
Anybody have any idea why? Am I still missing other
files from the other development system?? If so this will be a big problem since I gave the computer back thinking my c++ coding was done, no longer can build the dll.
Would appreciate any help on this
|
|
|
|
|
I think i have found you mistake,actually mfc42d.dll is used with debug version of DLL or app.
if you compile and build your dll in release version,it will then use mfc42.dll,which can easily found in any window based system.
actually,MFC42d.dll doesn't come with os,it comes with visual studio.i think now you understand my point
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
|
Thanks guys - that seems to be the problem area
I have managed to obtain some of the C++ stuff, but still no better. Surely the debug version can be run elsewhere (and not just on the sytem it was built on!)
|
|
|
|
|
I want to a barcode scanner.
But I want to write a program to be a interface for scanncer and user.
This program can get barcode scanncer's message(product ID),then send to My application program.
My application program get product ID,then show product info to Dialog's control.
Could you tell me how to write this program,or I can reference which web or data?
There is a problem,how do I create a barcode picture.
I write program by VC++6.0.
Did VC+++6.0 have barcode control? the name is called what?
When I print the barcode, do it distort(become more small or bigger)?
|
|
|
|
|
|
I had buy a Book Called "DirectX Effect".
I had read it,but I feel not enough.
Please Tell which book about DirectX3D is better.
I wish it will describe the detail about 3D Game Renader.
|
|
|
|
|
i recomand you OpenGL (NeHe's site, there i learnt a lot), but if you want to learn directX try the net, then buy books if you can't find what you want, usualy programing thechniques are found on the net too, game concepts are more dificult to find...
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
I have a List view ctrl. Now i could show the tooltip for each item. But the tooltip rect is too big and the text font is really ugly. I do not know where to set the tooltip's rect and text font, could any one help me?
Thanks a lot
|
|
|
|
|
Look at the articles in the ListCtrl/ListView section???
It's frustrating being a genius and living the life of a moron!!!
|
|
|
|
|
Here is a description of my problem. I have a modal dialogue window. In my OnInitDialog function, I may have to adjust the size of the window and it's contents manually because sometimes when the dialogue is constructed, an argument is passed into the constructor that turns off the display of certain controls within the window. So when the controls are off, I want to change the size of the window and remaining controls so that everything looks nicer (I don't want a huge blank spot in the middle of the window in this case).
So everything was working fine; I tried changing the window size of the dialogue and that worked fine. I know I can move buttons around and adjust them just like you do when a dialogue box is resizable by the user. But how do I resize a static group control? The group box is a border rectangle that surounds the controls and is just inside of the main dialogue. When I run the below bits of code, the GetClientRectangle function causes my system to crash. The group box is a CStatic control which inherits from CWnd. So it must have a rectangle, within the object, to describe it's coordinates. So why does GetClientRect fail? Is this not a valid function call for a CStatic control? If not, how do I get it's coordinates?
mGroupBox.GetClientRect(&myRect); //Crash!!!
//This would then adjust the height by 25%
mGroupBox.SetWindowPos(NULL, 0, 0, myRect.Width(),
(myRect.Height() - (myRect.Height()/4)),
SWP_NOMOVE | SWP_NOZORDER);
|
|
|
|
|
well.....
i dontsee anthing wrong.....
mGroupBox.GetClientRect(&myRect).....where mGroupBox happenz to be the CStatic Object
the "mGroupBox" IS A CWnd type and pointing to the static window(have u given the DDX control??).....once this is done.....use the SetWindowPos function(i have not used this,but i think maybe U HAVENT LINKED THE VARIABLE TO THE WINDOW USIND DDX maybe thatzthe prob).....
best of luck.....
happy programmin......
cheerz.....
|
|
|
|
|
The problem was that I was trying to implement the aforementioned code in my OnInitDialog method, prior to calling CDialog::OnInitDialog like so
BOOL UDxFilterDlg::OnInitDialog()
{
//NO! NO! Can't do this here. Must call
//CDialog::OnInitDialog(); first!
CRect rect;
mGroupBox.GetClientRect(&rect);
mGroupBox.SetWindowPos(NULL,
0,
0,
rect.Width(), (rect.Height() - (rect.Height()/3)),
SWP_NOMOVE | SWP_NOZORDER);
CDialog::OnInitDialog();
//Resize the group box below this point and it works fine!
//..rest of code
}
|
|
|
|
|
EMAIL s.w.kraft@netzero.net, WINXP Pro, MFC C++ 6.0
Supposedly one can pass arguments to a class by value or reference, no problem with value. However, code segment below:
//#include <iostream.h>
//Etc.
Workspace called "Cobject"
Create two classes:
Subobject1
Subobject2
Headers:
Subobject1.h
Subobject2.h
At initialize:
Subobject1 Initialize(float a, float b)
(results a,b defined)
Subobject2 Initialize(&a,&b)
(should pass a reference (address) to Subobject2, however,
get an error that says cannot convert float *a to float a
If I change Subobject2.h to Arguments &a, &b, still get error, not sure how to address the problem. According to
literature, should be able to pass arguments to a class
by reference without pointer logic, i.e. & arg to pass reference.
Would appreciate help on this one. Thanks in advance, Sid Kraft s.w.kraft@netzero.net;P
|
|
|
|