我正在搜索連接兩個字符串(由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