Solved

CString::Find an error...

Posted on 2000-04-03
17
532 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

636 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