Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assertion error on CString.GetAt

Status
Not open for further replies.

Vervoortje

Technical User
May 5, 2003
6
BE

i'm programming in MFC and when i compile i have 0 errors and 0 warnings !

But when i run the program it crashes on GetAt

CString woord;
char teken;
CString cletter;
int lengte = 0;

if((fscanf(stream, "%s", woord))!=EOF && status ==0)
{
lengte=woord.GetLength();
teken = woord.GetAt(lengte-1);
cletter.Format("%c",teken);
m_listbox.AddString(cletter);
}

i also tried woord[lengte -1 ], but same thing.

Here are my includes ( if needed)

#include "stdafx.h"
#include "FLA.h"
#include "FLADlg.h"

#include <afx.h>
#include &quot;String.h&quot;
#include <afxcoll.h>

The error msg says :

Debug assertion failed
File afx.inl
line 169
i took a look at that file and it tells me this :

_AFX_INLINE TCHAR CString::GetAt(int nIndex) const
{
ASSERT(nIndex >= 0);
ASSERT(nIndex < GetData()->nDataLength);
return m_pchData[nIndex];
}

Anyone any idea what the problem is and what to do about it ?
 
fscanf(stream, &quot;%s&quot;, woord)

%s stands for char array type, therefore passing in a CString type is incorrect. The reason it compiles is because the ellipses arguments are untyped.

-pete
I just can't seem to get back my IntelliSense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top