Solved

CString::Find an error...

Posted on 2000-04-03
17
525 Views
Last Modified: 2013-11-20

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.
0
Comment
Question by:peds
  • 6
  • 4
  • 2
  • +3
17 Comments
 
LVL 4

Expert Comment

by:captainkirk
ID: 2680492
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.
0
 

Author Comment

by:peds
ID: 2680517
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++;
}
0
 

Author Comment

by:peds
ID: 2680535
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++;
}
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:peds
ID: 2680584
Edited text of question.
0
 

Author Comment

by:peds
ID: 2680586
Adjusted points from 25 to 50
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2680689
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...
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2680695
oops. Je ne sais pas lire faut croire. Oublie ca.

--

Nevermind. It seems I can't read. Forget it.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 2680736
Your copied your code and tried it out. It is running absolutely OK
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2680764
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...
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2680996
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
0
 
LVL 1

Expert Comment

by:gaggio
ID: 2681043
This code is fine. The problem occurs in another function, this is pretty sure.
0
 
LVL 1

Accepted Solution

by:
gaggio earned 50 total points
ID: 2681050
This code is fine. The problem occurs in another function, this is pretty sure.
0
 

Author Comment

by:peds
ID: 2681115
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.
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 2681454
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...
0
 
LVL 2

Expert Comment

by:bbousquet
ID: 2681709
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]
0
 

Author Comment

by:peds
ID: 2681748
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!.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2682818
That's really unfortunate. Carelessly grading questions like that hurts everybody involved.

..B ekiM
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 95
format the code in java 6 94
pre4 challenge 19 100
"Black Box" Testing of Control System Software 2 51
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question