这是犹太人吗? [英] Is this kosher?

查看:74
本文介绍了这是犹太人吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计,


我刚写了一个函数来找到一行的结尾:


char * eol(char * pt )

{while(* pt!=''\'''&& * pt!=''\ n''&& * pt!=''\ 0'')//跑到线上

终结者角色

pt ++;

返回pt; //并返回指向它的指针

}


我这样使用它:


main()/ /我知道,我知道!

{char text_line [260],* t_pt;


/ * [获取文本路径到text_line] * /


t_pt = eol(text_line);

* t_pt =''\'''; //这会敲掉一个''\ n'',它会停止chdir()从

工作


chdir(text_line);

}


这样工作正常,但仅仅是为了实验,我更换了两行
含有t_pt的


* eol(text_line)=''\ 0'';


....并且它有效。这是一个语法上的事情吗?它是便携式的吗?我会

感谢你对此的教育评论。


多亏一堆,


MikeC。< br $>
-

竹子垃圾邮件机器人需要精神解密:


mike_best $ ntlworld * com

$ = @

* = dot

Folks,

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 line
terminator character
pt++;
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() from
working

chdir(text_line);
}

This works fine, but just for the experiment, I replaced the two lines
containing t_pt with

*eol(text_line) = ''\0'';

.... and it worked. Is this a syntactical thing to do? Is it portable? I''d
appreciate your educated comment on this.

Thanks a heap,

MikeC.
--
Mental decryption required to bamboozle spam robots:

mike_best$ntlworld*com
$ = @
* = dot

推荐答案

ntlworld * com
ntlworld*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 lines
containing 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 pointer
that eol() returns is guaranteed to be to a writeable character. In your
case, it is, provided that you only give writeable strings to eol().

Only give genuine null-terminated strings to eol() - an array of char
doesn''t /necessarily/ contain a string: char foo[3] = "foo"; being an
example 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.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


这篇关于这是犹太人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆