Solved

CString::Find an error...

Posted on 2000-04-03
17
522 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now