strlen计算长度char b[]{ɱ'},a[]123char b[]{1},a[]123int cstrlen(a),dstrlen(
strlen计算长度char b[]={'1'},a[]="123";
char b[]={'1'},a[]="123";
int c=strlen(a),d=strlen(b);
printf("%d %d\n",c,d);
b={'1'}
反汇编窗口
b的地址里面存的是:0x0012ff44每次都一样的
0012FF40 31 32 33 00 31 CC CC CC 88 123.1烫虉
0012FF49 FF 12 00 19 13 40 00 01 00 .....@...
输出结果: 3 7
b={'1','2'};
0012FF40 31 32 33 00 31 32 CC CC 88 123.12烫.
0012FF49 FF 12 00 19 13 40 00 01 00 .....@...
输出结果: 3 7
b={'1','2','3'};
0012FF40 31 32 33 00 31 32 33 CC 88 123.123虉
0012FF49 FF 12 00 19 13 40 00 01 00 .....@...
输出结果: 3 7
b={'1','2','3','4'};
0012FF40 31 32 33 00 31 32 33 34 88 123.1234.
0012FF49 FF 12 00 19 13 40 00 01 00 .....@...
输出结果: 3 7
b={'1','2','3','4','5'};
0012FF40 31 32 33 34 35 CC CC CC 88 12345烫虉
0012FF49 FF 12 00 19 13 40 00 01 00 .....@...
输出结果: 3 11
后序增加元素的话又是好几个11
以上都是VC6.0下,
这个到底是怎么一回事,不能理解这种现象,希望知道的可以解说下,谢谢了
strlen c
[解决办法]在VC6中,默认使用MBCS编码,即多字节字符集;而VC7、VC8以及VS默认的都是Unicode编码
[解决办法]strlen, wcslen, _mbslen, _mbstrlen
Get the length of a string.
size_t strlen( const char *string );
size_t wcslen( const wchar_t *string );
size_t _mbslen( const unsigned char *string );
size_t _mbstrlen( const char *string );
Routine Required Header Compatibility
strlen <string.h> ANSI, Win 95, Win NT
wcslen <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbslen <mbstring.h> Win 95, Win NT
_mbstrlen <stdlib.h> Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
Each of these functions returns the number of characters in string, excluding the terminal NULL. No return value is reserved to indicate an error.
Parameter
string
Null-terminated string
Remarks
Each of these functions returns the number of characters in string, not including the terminating null character. wcslen is a wide-character version of strlen; the argument of wcslen is a wide-character string. wcslen and strlen behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcslen strlen strlen wcslen
_tcsclen strlen _mbslen wcslen
_mbslen and _mbstrlen return the number of multibyte characters in a multibyte-character string. _mbslen recognizes multibyte-character sequences according to the multibyte code page currently in use; it does not test for multibyte-character validity. _mbstrlen tests for multibyte-character validity and recognizes multibyte-character sequences according to the LC_CTYPE category setting of the current locale. For more information about the LC_CTYPE category, see setlocale.
Example
/* STRLEN.C */
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void main( void )
{
char buffer[61] = "How long am I?";
int len;
len = strlen( buffer );
printf( "'%s' is %d characters long\n", buffer, len );
}
Output
'How long am I?' is 14 characters long
String Manipulation Routines
[解决办法]
Locale Routines
See Also setlocale, strcat, strcmp, strcoll Functions, strcpy, strrchr, _strset, strspn
[解决办法]
对齐,和CPU,操作系统,编译器都有关系,并且还是可选的,也可以通过预编译指令控制。
CPU 决定不对齐,有没有问题,有什么问题。
操作系统,决定如何处理,CPU的运行和编程模式;
比如Windows 32 Bits, 只有flat 一种模式,除非CPU 对不对齐,产生异常,
Windows 并不是很关心对齐的问题;
但是一般还是要求,32 Bits对齐。
而对有些特殊数据,则有一些特殊的对齐要求。
VC编译器 ,有一个对齐选项,可以决定一般数据,如何对齐,缺省是 32Bits,是可选的。
另外 有一条预编译指令,可以确定当前采取那种对齐方式。
VC还定义了一些非标准关键字,用于数据对齐。
其他编译器,应该也有类似的设置,以及对齐指令,或关键字。