显然,有很多缺失,例如: #define R return #define uns unsigned int #define FILE_m ????? #define fopen_m ????? #define GetLine_m ????? #定义free_m ????? #define fclose_m ????? 各种包括 如果有人认为_m函数是自定义的还是刚重新定义的ANSI C 函数? 我宁愿看主要定义为: int main(int argc,char ** argv) 所以,我知道什么是[1]而不必追踪 a是的位置定义。 s是一个指向char的指针,但你没有在C源代码中分配空间。 基于a + = 8; _malloc_m≤(一);"在下面的神秘代码部分,我怀疑你可能已经为s分配了空间。。但是,在可能被分配的唯一位置之前,你仍然将s设置为零, 而不是NULL。 我的个人偏好是查看参数如此写,return(0);, notreturn 0; ret 12 我不明白这个神秘的代码部分。你得到了程序集clc, 程序集标签.4,C运算符a + = 8,C-ish stuff_fgetc_m<(k), 评论带有单个和双正斜杠,还有一堆垃圾 带#和##。关于唯一可以全部工作的现有语言 一起是FORTH或者广泛的C预处理器滥用... 这个我理解作为x86程序集。它可能实际上是用FASM编译的。 1)C代码:没有。 2)神秘的伪FORTH-FASM-C-mixup:不。 3)x86汇编:是的。 为什么你发布没有人可以使用的代码?既不是a.l.a.或c.l.c.很可能 使用这个...... Rod Pemberton do you like the "GetLine_m" function i have written today?How many errors do you see?i have try only the option for to load the all [text] file in a stringnot the option to load a line "\n" ended so it should be full oferrors[but because i have the "len" i can load with that function the binaryfiles too]#define P printfint main(int c, char** a){ char *s;uns len;int i, n;FILE_m *f;/* ....open file */if(c<=1) return 0;f=fopen_m( a[1], "rb");if(f==0) {P("Errore apertura\n"); R 0;}len=0; s=0;n=GetLine_m(&s, &len, f); // per avere in s tutto il fileif(n==1) P("Tutto ok il file è = %s\n", s);else if(n==2) P("Errore di parametro\n");P("len=%u n=%i\n ", len, n);free_m(s); // alla fine s deve essere liberatofclose_m(f);return 0;} /* int __stdcall GetLine_m( char** s, uns* len, FILE* f)/* trash ecx, edx/* Assegna a "s" un indirizzo a una stringa contenente una/* linea di "f", (o tutto il file puntato da f se len==0)/* ritorna un codice di errore e assegna (se len!=0) ad len/* la lunghezza di tale stringa/* usare come in/* char *s;/* uns len;/* int i;/* FILE *f;/* ....open file/* ----------------------/* len=0; s=0;/* n=GetLine_m(&s, &len, f); // per avere in s tutto il file/* if(n==1) // tutto ok il file è in s e nessun errore/* else if(n==2) // errore di parametro etc/* free(s); // alla fine s deve essere liberato/* ----------------------/* len=12345678; s=0; n=GetLine_m(&s, &len, f); ... free(s);/* ----------------------/* s=0; n=GetLine_m(&s, &len, f); ... free(s);/* ----------------------/* ritorna 0 se tutto ok e EOF non raggiunto CF==0/* 1 Eof raggiunto e nessun errore trovato CF==0/* 2 errore parametro CF==1/* 3 errore memoria CF==1/* 4 errore lettura file CF==1/* 5 errore file troppo grande per la memoria CF==1/*/* 0k, 4j, 8i, 12b, 16Ra, 20P_s, 24P_len, 28P_fGetLine_m:< b, i, j, ka=^20; k=^28; a==0#.e2; k==0#.e2;i=0; b=*a; j=2; // era j=64b#.1; a=j; a+=8; _malloc_m<(a);a==0#.e3; b=a; a=^20; *a=b; #.1;..e2: a=2; #.e; / errori di parametro..e3: a=3; #.e; / errori di memoria..e4: a=4; #.e; / errori di overflow indice..e5: a=5; / errori di lettura file..e: stc; ##.f / below the loop..1: j&i!#.2 | j+=i; jc .e4; a=j; a+=8; jc .e4;| _realloc_m<(b, a);| a#.2b | r=^24; r==0#.2a; *r=i;..2a: | #.e3;..2b: | b=a; a= ^20; *a=b;..2: _fgetc_m<(k); a==-1!#.3| r=^24; B[b+i]=0; r==0#.2d| *r=i;..2d: | D [k+12]& 16 #.e5 // ferror(k)?| k=1; #.8; // EOF..3: [b+i]=al; ++i; jz .e4; r=^24; r==0#.4; D*r==0#.1; i>=*r#.5;..4: al!=10#.1; #.6;..5: r=^24; B[b+i]=0; r==0#.e4; *r=i; ##.e4;..6: r=^24; B[b+i]=0; r==0#.7; *r=i;..7: k=0;..8: a=i; a+=4; _realloc_m<(b, a); a==0#.e4;b=a; a=^20; *a=b;a=k; clc;..f:ret 12 GetLine_m:push ebxpush esipush edipush ebpmov eax, [ esp + 20 ]mov ebp, [ esp + 28 ]cmp eax, 0je .e2cmp ebp, 0je .e2mov esi, 0 ;/ era j=64mov ebx, [eax]mov edi, 2cmp ebx, 0jne .1mov eax, ediadd eax, 8push eaxcall _malloc_madd esp, 4cmp eax, 0je .e3mov ebx, eaxmov eax, [ esp + 20 ]mov [eax], ebxjmp short .1..e2: ; errori di parametromov eax, 2jmp short .e..e3: ; errori di memoriamov eax, 3jmp short .e..e4: ; errori di overflow indicemov eax, 4jmp short .e..e5: ; errori di lettura filemov eax, 5..e:stcjmp .f..1:test edi, esijz .2add edi, esijc .e4mov eax, ediadd eax, 8jc .e4 push eaxpush ebxcall _realloc_madd esp, 8 cmp eax, 0jne .2bmov edx, [ esp + 24 ]cmp edx, 0je .2amov [edx], esi..2a: jmp short .e3..2b: mov ebx, eaxmov eax, [ esp + 20 ]mov [eax], ebx..2:push ebpcall _fgetc_madd esp, 4cmp eax, -1jne .3mov edx, [ esp + 24 ]mov byte[ebx+esi], 0cmp edx, 0je .2dmov [edx], esi..2d: ;/ ferror(k)? test dword [ebp+12], 16jnz .e5;/ EOFmov ebp, 1jmp short .8..3:mov [ebx+esi], alinc esijz .e4mov edx, [ esp + 24 ]cmp edx, 0je .4cmp dword[edx], 0je .1cmp esi, [edx]jae .5..4:cmp al, 10jne .1jmp short .6..5:mov edx, [ esp + 24 ]mov byte[ebx+esi], 0cmp edx, 0je .e4mov [edx], esijmp .e4..6:mov edx, [ esp + 24 ]mov byte[ebx+esi], 0cmp edx, 0je .7mov [edx], esi..7:mov ebp, 0..8:mov eax, esiadd eax, 4push eaxpush ebxcall _realloc_madd esp, 8cmp eax, 0je .e4mov ebx, eaxmov eax, [ esp + 20 ]mov [eax], ebxmov eax, ebpclc..f:pop ebppop edipop esipop ebxret 12 解决方案 Nine. -- Er*********@sun.com^^^^^^^^^^^^^^^^Oh shit, he''s back.^^^undefined type^^^^^^undefined type [remaineder of unindented C-like-but-not-quite-C code and large amountsof nothing-like-C code snipped]Follow ups to this post set to a.l.a. I don''t like your C coding style. #define P printf int main(int c,char **a){char *s;uns len;int i, n;FILE_m *f;/* ....open file */if(c<=1)return(0);f=fopen_m(a[1],"rb");if(f==0){P("Errore apertura\n");R(0);}len=0;s=0;n=GetLine_m(&s,&len,f); // per avere in s tutto il fileif(n==1){P("Tutto ok il file è = %s\n",s);}else{if(n==2)P("Errore di parametro\n");}P("len=%u n=%i\n ",len,n);free_m(s); // alla fine s deve essere liberatofclose_m(f);return(0);} Obviously, there is much missing, like: #define R return#define uns unsigned int#define FILE_m ?????#define fopen_m ?????#define GetLine_m ?????#define free_m ?????#define fclose_m ?????various includes Should one assume that the _m functions are custom or just redefined ANSI Cfunctions? I''d rather see main defined as:int main(int argc,char **argv) So, that I know what a[1] is without having to track down the location wherea is defined. s is a pointer to char, but you didn''t allocate space in the C source.Based on "a+=8; _malloc_m<(a);" in the cryptic code section below, I suspectthat you may have allocated space for s. However, you still set s to zero,instead of NULL, before the only place where it might be allocated. My personal preference is to see arguments written as such, "return(0);",not "return 0;". ret 12 I don''t understand this cryptic code section. You got assembly "clc",assembly labels ".4", C operators "a+=8", C-ish stuff "_fgetc_m<(k)",comments with both a single and double forward slash, and a bunch of junkwith # and ##. About the only existing language that could that all to worktogether is FORTH or perhaps extensive C pre-processor abuse... This I understand as x86 assembly. It might actually compile with FASM. 1) C code: No.2) cryptic pseudo-FORTH-FASM-C-mixup: No.3) x86 assembly: Yes. Why do you post code nobody can use? Neither a.l.a. or c.l.c. is likely touse this ever...Rod Pemberton 这篇关于我的getline比你的好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 18:09