strcpy() 与 ‘\0’
          
            时间:03-16 10:40 阅读:1658次
*温馨提示:点击图片可以放大观看高清大图
                
         
        
		  
               简介:strcpy() 拷贝字符串,它直到发现'\0'字符串结束符才结束,所以,有时候使用它会出现错误。
               
                        
          
            strcpy() 拷贝字符串,它直到发现'\0'字符串结束符才结束,所以,有时候使用它会出现错误。
void main()
{
char str[10],str0[10];
for(int i=0;i<10;i++)
  str[i] = 'd';
 strcpy(str0,str);
 return 0
}    // 程序结束会出现  run-time check failure #2 _stack around the variable 'str' was corrupted
应该改成
void main()
{
char str[10],str0[10];
for(int i=0;i<10;i++)
  str[i] = 'd';
 str[9] = '\0';
 strcpy(str0,str);
 return 0
}