URL: https://www.overclockers.at/coding-stuff/c_laenge_eines_strings_an_einem_char_pointer_99683/page_1 - zur Vollversion wechseln!
char* s1 = "wasweisich";
Gibts hier irgendeinen schmäh wie man die Länge dieses Strings herausfindet ohne die Klassenbibliothek zu verwenden?
edt: geht doch ned
afair
#include <string.h>
size_t strlen(const char *s);
Zitat von funkaafair
#include <string.h>
size_t strlen(const char *s);
dann mach eine whileschleife die bis zum \0 mitzaehlt steck das ganze in eine funktion und nenns strlen_bydummies()
EDIT: ups, angabe falsch gelesen
sry
MFG
-ICH-
semtex und braindeath
beide in die ecke
hop
wenn sogar funk mehr c knowledge hat wirds peinlich
soda für die nachwelt, habs hingebracht:
int length_for_dummies(const char* t)
{
int k=0;
while(*(t+k)!='\0') k++;
return k;
}
Danke an alle!
also hätts doch gestimmt naaa
Ein bissi kürzer
Code:int length_for_dummies(const char* t) { int k=0; while(*t++) k++; return k; }
int strlen (char str[])
{
int i=0;
while (str[i] != '\0')
{
i++;
} /* while */
return (i);
}//strlen
wäre auch ne möglichkeit
Zitat von Ecraftschön wärs... unsere praktikum tussi will das nicht!!!! Der wär am liebsten das Rad neu zu erfinden!
Code:CODESEG public strlen strlen proc .FPO ( 0, 1, 0, 0, 0, 0 ) string equ [esp + 4] mov ecx,string ; ecx -> string test ecx,3 ; test if string is aligned on 32 bits je short main_loop str_misaligned: ; simple byte loop until string is aligned mov al,byte ptr [ecx] inc ecx test al,al je short byte_3 test ecx,3 jne short str_misaligned add eax,dword ptr 0 ; 5 byte nop to align label below align 16 ; should be redundant main_loop: mov eax,dword ptr [ecx] ; read 4 bytes mov edx,7efefeffh add edx,eax xor eax,-1 xor eax,edx add ecx,4 test eax,81010100h je short main_loop ; found zero byte in the loop mov eax,[ecx - 4] test al,al ; is it byte 0 je short byte_0 test ah,ah ; is it byte 1 je short byte_1 test eax,00ff0000h ; is it byte 2 je short byte_2 test eax,0ff000000h ; is it byte 3 je short byte_3 jmp short main_loop ; taken if bits 24-30 are clear and bit ; 31 is set byte_3: lea eax,[ecx - 1] mov ecx,string sub eax,ecx ret byte_2: lea eax,[ecx - 2] mov ecx,string sub eax,ecx ret byte_1: lea eax,[ecx - 3] mov ecx,string sub eax,ecx ret byte_0: lea eax,[ecx - 4] mov ecx,string sub eax,ecx ret strlen endp end
g0t assembler ??
Von dir oder abgeschrieben?
Schaut irgendwie aus, als käme es aus der MS CRT.
### ups... ###
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025