如同诚心对待上帝一样诚心求教!!!!!基础问题
很基础的问题,小羊已经手上无分可送,请各位大虾不吝赐教,以下两个字符串究竟哪里不同了?为什么C写的结果会那么异常呢?
用标准库的函数当然没问题,我很想知道下面这个函数到底怎么个不对法,谢谢.
/*结果:
string:ABCDE烫烫烫誊? length:15 size:5
string:ABCDE length:5 size:5
*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
void foo_forc()
{
char buf[5];
int nChar=0x41;
memset(buf,0,5);
for(int i=0;i<5;i++)
{
buf[i]=(char)nChar;
nChar++;
}
printf("string:%s\tlength:%d\tsize:%d\n",buf,(int)strlen(buf),sizeof(buf));
getch();
}
void foo_forasm()
{
char buf[5];
__asm
{
lea edi,buf
mov eax,41h
mov ecx,05h
lo:
mov [edi],eax
inc eax
inc edi
loop lo
}
printf("string:%s\tlength:%d\tsize:%d\n",buf,(int)strlen(buf),sizeof(buf));
getch();
}
void main()
{
foo_forc();
foo_forasm();
}