-
May 22nd, 2004, 03:10 AM
#1
_mbsnbcnt() problems
hi,everyone
I want to use the _mbsnbcnt() to get the bytes number of a string
my code is as follows:
define CHAR_PER_LINE 30
char *pBuf=new char[100];
memset(pBuf,32,100);
int my function:i first read in string from the txt file,and then use
the following line:
int nLen=_mbsnbcnt( (unsigned char*)pBuf,CHAR_PER_LINE);
when i check the value of the nlen , i found that some times it larger than the CHAR_PER_LINE,why?
-
May 22nd, 2004, 09:48 AM
#2
Looks like you miss the terminating zero at your stringĀ“s end. Maybe this helps:
Code:
#define CHARS_PER_LINE 30
#define BUFFER_SIZE 100
char *pBuf = new char[BUFFER_SIZE];
if( pBuf ) {
memset( pBuf, 0, BUFFER_SIZE );
// read max. BUFFER_SIZE -1 characters into your buffer
int nLen=_mbsnbcnt( (unsigned char*)pBuf,CHAR_PER_LINE);
}
Second, maybe the lines you read from your file are longer that 30 characters?
Good Luck,
Guido
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|