Solved

CString::Find an error...

Posted on 2000-04-03
17
527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 152
matchUp  challenge 9 124
Problem to App 4 116
I could not set window to top 4 40
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

762 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