我正在搜索连接两个字符串(由C传递)将结果放在第三个字符串中。我做到了,但知道我想在琴弦之间放一个空间,但是......这不可能......! 这是C的部分把连接字符串之间的空格
#include <stdio.h>
#include <string.h>
void concatena(char *stringa, char *stringa2, char *dest);
int main(void)
{
char stringa[17] = { "stringa numero 1" };
char stringa2[17] = { "stringa numero 2" };
char dest[34] = { "" };
concatena(stringa, stringa2, dest);
printf("%s", dest);
getchar();
}
调用的MASM32的一部分:
.586
.model flat
.code
_concatena proc
;pre
push ebp
mov ebp,esp
push ebx
push edi
push esi
;clean
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
mov eax, dword ptr[ebp+8] ;source=stringa
mov ebx, dword ptr[ebp+12] ;target=stringa2
mov ecx, dword ptr[ebp+16] ;buffer=dest
inizio:
mov dl,byte ptr[eax+esi*1]
cmp dl,0
je space ;first string finished
mov byte ptr[ecx+esi*1], dl
inc esi
jmp inizio
space:
inc esi
mov byte ptr[ecx+esi*1],32
;if i put a 'inc esi' here the result is the same
jmp fine1
fine1:
mov dl, byte ptr[ebx+edi*1]
cmp dl, 0
je fine2 ;second string finished
mov byte ptr[ecx+esi*1], dl
inc edi
inc esi
jmp fine1
fine2:
;post
pop esi
pop edi
pop ebx
pop ebp
ret
;chiusura della procedura
_concatena endp
end
当我在输出运行它,我看到:
你怎么看concatena ()放在目标数组中只有第一个字符串... 非常感谢您的每一个答案!
如果你想要一个空间,添加它。如果你不添加它,C不会。这一切都在你的掌控之中。权力是责任。 –
首先以高级语言编写函数,然后将其翻译为程序集。错误是你的代码在没有混淆的情况下会非常明显。 – EOF
更好:'无效concatena(const char * stringa,const char * stringa2,char * dest);'和'printf(“%s \ n”,dest);'也许在结束大括号前加上'return 0;' 'main()' – pmg