* eol(text_line)=''\ 0''; ....并且它有效。这是一个语法上的事情吗?它是便携式的吗?我会 感谢你对此的教育评论。 多亏一堆, MikeC。 - 竹子垃圾邮件机器人需要精神解密: mike_best $ ntlworld * com $ = @ * = dotFolks,I just wrote a little function to find the end of a line:char *eol(char *pt){ while(*pt != ''\r'' && *pt != ''\n'' && *pt != ''\0'') // run along to the lineterminator characterpt++;return pt; // and return a pointer to it}I use it thus:main() // I know, I know!{ char text_line[260], *t_pt;/* [ get a file path into text_line] */t_pt = eol(text_line);*t_pt = ''\0''; // this knocks off a ''\n'', which stops chdir() fromworkingchdir(text_line);}This works fine, but just for the experiment, I replaced the two linescontaining t_pt with*eol(text_line) = ''\0'';.... and it worked. Is this a syntactical thing to do? Is it portable? I''dappreciate your educated comment on this.Thanks a heap,MikeC.--Mental decryption required to bamboozle spam robots:mike_best$ntlworld*com$ = @* = dot推荐答案 ntlworld * comntlworld*com = @ * = dot= @* = dot MikeC说: < snip>MikeC said:<snip> > 这样工作正常,但仅仅是为了实验,我更换了两行 包含t_pt with * eol(text_line)=''\ 0''; ......它有效。这是一个语法上的事情吗?它是便携式的吗?>This works fine, but just for the experiment, I replaced the two linescontaining t_pt with *eol(text_line) = ''\0'';... and it worked. Is this a syntactical thing to do? Is it portable? 是的,没关系,只要你绝对100%确定eol()返回的指针 是保证的是一个可写的角色。在你的 情况下,只要你只给eol()提供可写字符串。 只给eol()提供真正的以空字符结尾的字符串 - 一个char数组不一定/不包含字符串:char foo [3] =" foo" ;;是一个没有的例子。如果你计划做你的* eol()的事情, 不要给eol()一个字符串文字来提供: * eol (哦,deary deary me\ n)=''\'''; / *要求麻烦* / char * p =" oh deary deary me\ n"; * eol(p)='' \0 ''; / *仍然要求同样的麻烦* / char arr [] ="但这没关系\ n"); * eol( arr)=''\'''; / *没有汗水* / - Richard Heathfield Usenet是一个奇怪的地方 - dmr 29/7/1999 http://www.cpax.org.uk 电子邮件:正常服务将尽快恢复。请不要 调整您的电子邮件客户端。Yes, it''s fine, provided you are absolutely 100% certain that the pointerthat eol() returns is guaranteed to be to a writeable character. In yourcase, it is, provided that you only give writeable strings to eol().Only give genuine null-terminated strings to eol() - an array of chardoesn''t /necessarily/ contain a string: char foo[3] = "foo"; being anexample of one that does not. And if you plan to do your *eol() thing,don''t give eol() a string literal to feed on:*eol("oh deary deary me\n") = ''\0''; /* asking for trouble */char *p = "oh deary deary me\n";*eol(p) = ''\0''; /* still asking for the same trouble */char arr[] = "but this is okay\n");*eol(arr) = ''\0''; /* no sweat */--Richard Heathfield"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.ukemail: normal service will be restored as soon as possible. Please do notadjust your email clients. 这篇关于这是犹太人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-30 04:14