|
It's straight C ? If it were me, I'd start commenting things out until I found which bit is causing the problem. How big is the function ? Can you post some code ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
You're *sure* it's not a stack overflow then ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
If you can localize the problem to a specific function (by selectively commenting out other stuff), go ahead and post the code (and the sample data you feed it). It should be relatively easy to spot the problem.
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
// ahum, sorry!
/*
ok ravi, YOU asked for it!!! nah, looks scary but ain't. just look at the function tryRule, or, the one that calls it, readStrings. rest is just file reading and formatting stuff. i'm sure you'll see the cause of the problem.
************************************
these four lines have to be placed as a text file, say grammar.txt
S -> Saabb | ccc | $
S -> kTk
T -> pppter
T -> pppalter
*************************************
these two lines may be put in another text file, say strings.txt
gyrwweweweerrw
kpppalterkaabb
******************************************
this is the code. command line parameters are
1. the grammar file,
2. the strings file
3. any file for getting the results.
******************************************
*/
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
int countGrammarLines(char*);
void readGrammar(int, char**, char*);
void readStrings(char**, char*, char*);
bool tryRule (int, char**, char *, char* &);
int countGrammarLines(char* grammarFile)
{
int count=0;
char line[100];
char *token;
token = new (char) (100);
ifstream fin(grammarFile, ios::nocreate);
if (!fin) {
cout << grammarFile << ": File not found" << endl
<< "Exiting the application!" << endl;
exit(0);
}
while (!fin.eof()) {
fin.getline(line, 100, '\n');
count++;
token = strtok(line, "|");
while (token != NULL) {
count++;
token = strtok(NULL, "|");
}
--count;
}
fin.close();
return count;
}
void readGrammar(int count, char** rules, char* grammarFile)
{
char line[100];
char *token;
ifstream fin(grammarFile, ios::nocreate);
if (!fin) {
cout << grammarFile << ": File not found" << endl
<< "Exiting the application!" << endl;
exit(0);
}
for (int i=0; i<count; i++) {
fin.getline(line, 100, '\n');
token = strtok(line, "|");
*(rules[i]) = *token;
strcpy (rules[i]+1, token+5);
if (*(rules[i] + strlen(rules[i])-1) == ' ')
*(rules[i] + strlen(rules[i])-1) = '\0';
token = strtok(NULL, "|");
while (token != NULL) {
i++;
*(rules[i]) = line[0];
strcpy (rules[i]+1, token+1);
if (*(rules[i] + strlen(rules[i])-1) == ' ')
*(rules[i] + strlen(rules[i])-1) = '\0';
token = strtok(NULL, "|");
}
}
fin.close();
}
void readStrings(int count, char** rules, char *stringFile, char *resultFile)
{
char *line = new (char) (100);
int strCount = 1;
bool result = false;
ifstream fin(stringFile, ios::nocreate);
ofstream fout(resultFile);
if (!(fin)) {
cout << stringFile << " : File not found" << endl
<< "Exiting the application!" << endl;
exit(0);
}
while (!fin.eof()) {
fin.getline(line, 100, '\n');
for (int i=0; i<count; i++) {
fout << strCount++ << ". ";
if (*rules[i] == 'S') {
if (tryRule (count, rules, (rules[i]+1), line)) {
result = true;
break;
}
}
}
fout << (result ? "accepted" : "rejected") << endl;
cout << (result ? "accepted" : "rejected") << endl;
}
fin.close();
fout.close();
}
bool tryRule (int count, char** rules, char *rule, char* &str)
{
char *temp;
char *newrule = new (char) (2 * strlen(str));
bool result = false;
while (*rule == *str && *rule != 0 && *str != 0) {
rule++;
str++;
}
temp = str;
if (*rule == 0 && *str == 0)
return true;
else if (*rule == '$')
return tryRule (count, rules, ++rule, str);
else if (*rule >= 'A' && *rule <= 'Z') {
for (int i=0; i<count; i++) {
if (*rules[i] == *rule && (strlen(rules[i]) + strlen(rule)) <= 3 + strlen(str)) {
strcpy (newrule, rules[i]+1);
strcat (newrule, rule+1);
result = result || tryRule (count, rules, newrule, str);
if (result)
break;
else
str = temp;
}
else
result = false;
}
}
return result;
}
int main(int argc, char *argv[])
{
char **rules;
int count;
count = countGrammarLines(argv[1]);
rules = new (char*[count]);
for (int i=0; i<count; i++)
rules[i] = new (char) (100);
readGrammar(count, rules, argv[1]);
readStrings(count, rules, argv[2], argv[3]);
return 0;
}
|
|
|
|
|
hhh wrote:
ok ravi, YOU asked for it!!!
One request - can you repost (or just modify your message) and check the "Display the message as-is (no HTML)" box? That will include the #includes and will show the indenting clearer. Thanks!
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
|
When you post an #include, if it uses the < and > symbols, the contents of the include statment are lost unless you check 'display as is'. Obviousl you have such an include and because you didn't check it, Ravi can't tell what you're including.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I'm having a hell of a time replying here, I think you must be deleting posts ?
Anyhow, you said
Tim
i'm afraid i'm correct there, i AM getting memory allocated equal to 100 * sizeof(char) bytes somewhere. your suggested statement is considered illegal by some compilers - i'm using MS VC++
and I am trying to reply with this:
Tim is right, under VC++ the statement char * pChar = new char [100] allocates an array of 100 chars, and the statement char * pChar = new (char) (100) will ignore the first set of brackets and create room for one char, initialised to 100. I don't know what strange settings could cause VC to barf when asked to allocate an array, or why you think your statement creates an array, it quite plainly does not.
I'm guessing you've realised you were wrong ? In any case, char * pChar = new char[100]; is so valid that any compiler that rejects it should be burned at the stake.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
char *text = new (char) (100);
What are you trying to do here?
1. Allocate 100 characters?
2. Allocate 1 character initialized to 100?
The code does #2. If you want to do #1:
char *text = new char [100];
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
LOL, well ok.
Don't say I didn't try to help.
You might want to actually try to debug you code and see exactly what "char *array = new (char) (count)" actually does. Which is what I did. It equates to the code:
char *array = new char [1];
array [0] = count;
new operator
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
sorry tim, i didn't mean to sound or act rude, i very much appreciate your concern. i tried what you're suggesting, and i can't get it to work here.
thanx for your help, again.
imran.
|
|
|
|
|
well, what should i say, you're absolutely right. i'm awfully sorry for my stubborness, but i'll find an excuse, i've been awake all night...
imran.
|
|
|
|
|
Heh, no problem.
I just hope I didn't come across too bitchy.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Are you by any chance calling code in a non-MFC DLL from an MFC app? (Beware of heap issues).
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
hhh wrote:
hi to all the great developers out there!
what could be the reason for a program to crash at the last statement i=e, return 0?
the message is something like the instruction at location xxxx tried to reference memory at location xxxx. the memory could not be written.
please help, i'm stuck!
What is your problem ? Why are you deleting all your posts ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
i guess there were a lot of useless posts there by me! but my problem seems to have been solved, thanx to Tim, and to you all, really.
imran.
|
|
|
|
|
I apologize for not getting back to you. I'm glad Tim was able to help and you're up and running.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi all,
I'm using multiple languages in my Windows ...
For example: English US - French !
I wanna is any function or way for changing language ?
For example, i'm writing text in Notepad ...
Then i running my program, i wanna change my language from English to French, programitically !
Help me !
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Take a look at GetKeyboardLayout and ActivateKeyboardLayout APIs.
|
|
|
|
|
There's a following problem:
I use ADO to get some recordset from SQLServer2000.
the sql string is the following:
select * from Orders where EmployeeID='1' FOR XML AUTO
As You can see, I want the results to be in XMLform.
The problem is that sometimes (very often, when I want a
huge amount of data) the returned XML is not well formed !.
Of course I supply the single root element for entire
output (e.g wrapping everything in <some_element>).
The error is very subtle:
sometimes within document there are new-line characters in places
where they cant be .They are within attributes names.
For example:
ShipName="Bon app'" ShipAd
dress="12, rue des Bouchers" ShipCity="Marseille"
You can see that ShipAddress attribute is divided to
2 lines, whlist it must not.
The string I get is in this form immediately after having been
returned by the SQLSever (ADO method call) . Later, w hen I load
it using MSXML Parser
it seems to be not-well-formed. Also when saved the returned
string to file, and opened it with XML spy , it declares that
the file is wrong (not-well-formed), indicationg the very errors.
I use (I guess) the oldest version of SQLSrv2000 => this means
that it's without any patches or upgrades (if it matters anything)
What should I do to solve the problem ?
Please Help
Michal Januszczyk
|
|
|
|
|
I got some code contains a loop which execuates for about 20000 times.How can
I step into the 10000th execuation?
|
|
|
|
|
> How can I step into the 10000th execuation?
Conditional Breakpoints.
Open the Breakpoints dialog (Edit-Breakpoints or Alt+F9 in DevStudio 6.0), specify the location (or select a previously marked Breakpoint, which is easier), and then click on Condition... to specify a condition for the Breakpoint.
Peace!
-=- James.
|
|
|
|
|
Your condition should be something like
i == 10000
Todd Smith
|
|
|
|
|
if (i == 10000)
__asm int 3;
It is faster than conditional breakpoints.
I vote pro drink
|
|
|
|
|
Hi,
I´m trying to get the size of the paper when printing ( I just want to fit a metafile in the size of the paper), to get the size of the paper I tried this:
CSize himetricPrinter(pDC->GetDeviceCaps(HORZSIZE)*100, pDC->GetDeviceCaps(VERTSIZE)*100);
pDC->HIMETRICtoDP(&PaperSize); // Printer DC
The that value I use it to play the metafile.
And then I got wrong values ( For the Y axis). Can anybody help me ?, Thanks, Bye !
Braulio
|
|
|
|
|