Link to home
Start Free TrialLog in
Avatar of peds
peds

asked on

CString::Find an error...


I'am developping a search algorithm in Visual C++.
I wonder if anyone could help me resolve my little problem.

I'am using a Find function with CString class in a MFC project.
This error message appears and my program's execution stops.

First-chance exception in Uni.exe (MFC42D.DLL): 0xC0000005: Access Violation.

If you have any information please send it to me at:

Thanks


Bonjour, je développe en Visual C++ et ce message d'erreur apparait alors que j'exécute une fonction Find sur un CString. Quelqu'un peut m'aider?

First-chance exception in Uni.exe (MFC42D.DLL): 0xC0000005: Access Violation.
Here is my code.
The NETTextValue is a CString passed by another function.
The Debug stops on the NETTextValue.Find line after the third passage.

//Récupérer et séparer les numéros de rubrique
////////////Traitement de NET_TEXT///////////////
/// le texte(NETTEXTValue looks like: "111/112/44/234/f"

CString token[3];
int w =0;
int r=0;
int indexDebut = 0;
int indexNombre = 0;
int Reponse;//ID_NET
int max;
max=NET_TEXTValue.GetLength();
while (indexNombre < (max-2))//ne pas compter le dernier <</>> ni le <<f>> de fin
{      (indexNombre = NET_TEXTValue.Find ('/',r));
      token[w] = NET_TEXTValue.Mid(r,(indexNombre-r));
      r= indexNombre+1;
      AfxMessageBox(token[w]);
      w++;
}
the point is to separate those numbers in those 3 tokens.
Avatar of captainkirk
captainkirk

Pourrez-vous me donnez votre code?? Je voudrais plus d'information, s'il vous plait...

now that I've just about exhausted all the French I remember, the jist of the problem is that we would need to see your code - how you are treating the CString object.
Avatar of peds

ASKER

Capt'n Kirk...
Voici le code en question.
Le Debug arrête à la ligne
du find au troisième passage.

//Récupérer et séparer les numéros de rubrique
////////////Traitement de NET_TEXT///////////////
/// le texte(NETTEXTValue ressemble à: "111/112/44/234/f"

CString token[3];
int w =0;
int r=0;
int indexDebut = 0;
int indexNombre = 0;
int Reponse;//ID_NET
int max;
max=NET_TEXTValue.GetLength();
while (indexNombre < (max-2))
//ne pas compter le dernier <</>> ni le //<<f>> de fin
{      (indexNombre = NET_TEXTValue.Find ('/',r));
token[w] = NET_TEXTValue.Mid (r,(indexNombre-r));
      r= indexNombre+1;
      AfxMessageBox(token[w]);
      w++;
}
Avatar of peds

ASKER

My code is
//Récupérer et séparer les numéros de rubrique
////////////Traitement NET_TEXT///////

///le CString(NETTEXTValue as the value: "111/112/44/234/f"
//it is passed by another function
CString token[3];
int w =0;
int r=0;
int indexDebut = 0;
int indexNombre = 0;
int Reponse;//ID_NET
int max;
max=NET_TEXTValue.GetLength();
while (indexNombre < (max-2))//ne pas compter le dernier <</>> ni le <<f>> de fin
{      (indexNombre = NET_TEXTValue.Find ('/',r));
      token[w] = NET_TEXTValue.Mid(r,(indexNombre-r));
      r= indexNombre+1;
      AfxMessageBox(token[w]);
      w++;
}
Avatar of peds

ASKER

Edited text of question.
Avatar of peds

ASKER

Adjusted points from 25 to 50
Le problème est le suivant:

int max;

Tu n'as pas initialisé la variable! Ta boucle 'while' se base sur cette variable non initialisée pour fonctionner...

---

You forgot to initialize max to a proper value! Thus your while loop is not reliable at all as it relies on max...
oops. Je ne sais pas lire faut croire. Oublie ca.

--

Nevermind. It seems I can't read. Forget it.
Your copied your code and tried it out. It is running absolutely OK
Ton code a un problème: CString token[3] a une dimension de 3. Je l'ai roulé sur ma machine et il fonctionne mais cause un débordement au niveau du 4e token...

--

Your code definitely has a problem. CString token[3] has a size of 3. It runs properly on my machine but there's an overflow of the token array...
I'm a little conflused. A first-chance exception should not cause your program to "just stop executing".

How are you convinced that this code is what's causing the exception?  As other people have pointed out, you have a couple of potential problems. But I want to see the certainty that relates the message to this code.

Have you trapped the exception in the debugger? What's the stack trace for that? What line of code, _exactly_, in MFC is causing the exception? Which version of VC++ and MFC are you using?

..B ekiM
This code is fine. The problem occurs in another function, this is pretty sure.
ASKER CERTIFIED SOLUTION
Avatar of gaggio
gaggio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peds

ASKER

I really liked to see that so many people answered my question. I think my problem is on my computer...
Thanks a lot I'll surely be back!
Peds.
Je suis heureux que vous avez trouvé ce que vous cherchez. Je n'ai pas récu des messages de notifications, parce que je crois que c'est ici un problème avec email...
Why the heck did gaggio get the points? He didn't say anything at all!

Weird stuff.

[And you WERE going out of bounds with your token[] array]
Avatar of peds

ASKER

I didn't understand the way it's going on here. S'cuse me if you wanted some points.Anyway we won't see each other many times since I have no more points. And my code still don't work. To bad!.
That's really unfortunate. Carelessly grading questions like that hurts everybody involved.

..B ekiM