相当于perl中的chomp [英] equivalent of chomp in perl

查看:68
本文介绍了相当于perl中的chomp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在C中是否有与perl命令chomp相同的效果?如果有

没有完全相同的命令,我将如何删除\ n在

结束了stdin?


谢谢,

娜塔莉

Hi,
Is there an equivalent to the perl command chomp in C? And if there is
no exact equivalent command, how would I go about removing the "\n" at
the end of a stdin?

Thank you,
Natalie

推荐答案

" lnatz" < nm ********** @ gmail.comwrites:
"lnatz" <nm**********@gmail.comwrites:

是否有与C语言中的perl命令chomp相同的?
Is there an equivalent to the perl command chomp in C?



编号(chomp从字符串末尾删除''\ n''字符。)

No. (chomp removes a ''\n'' character from the end of a string.)


如果没有完全相同的命令,我该如何去除

删除\ n在标准结束时?
And if there is no exact equivalent command, how would I go about
removing the "\n" at the end of a stdin?



我认为a stdin是指从stdin获得的字符串。


搜索对于''\ n''字符,并将其替换为''\'''。准备

来决定如果字符串不包含''\ n''字符该怎么办,

或者如果它包含一个但不包含结束。


注意C字符串不像Perl字符串。他们不会自动重新调整自己的大小。 C字符串不是数据类型;它是

数据*格式*,由''\0''终止的字符序列。字符串

通常保存在char数组中;将尾随''\ n''更改为

''\ 0''将更改字符串的长度,但不会更改

数组的大小。


-

Keith Thompson(The_Other_Keith) ks *** @ mib。 org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

I presume that by "a stdin", you mean "a string obtained from stdin".

Search for the ''\n'' character and replace it with ''\0''. Be prepared
to decide what to do if the string doesn''t contain a ''\n'' character,
or if it contains one but not at the end.

Note that C strings are not like Perl strings. They don''t
automatically re-size themselves. A C string isn''t a data type; it''s
a data *format*, a sequence of character terminated by ''\0''. A string
is typically held in an array of char; changing a trailing ''\n'' to
''\0'' will change the length of the string but not the size of the
array.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


lnatz写道:
lnatz wrote:

>

C中是否有与perl命令chomp等效的内容?如果

没有完全相同的命令,我将如何去除

删除\ n在标准结束时?
>
Is there an equivalent to the perl command chomp in C? And if
there is no exact equivalent command, how would I go about
removing the "\n" at the end of a stdin?



int flushln(FILE * f){

int ch;


while(( ''\ n''!=(ch = getc(f)))&&(EOF!= ch))继续;

返回ch;

}


-

Chuck F(cinefalconer at maineline dot net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home.att.net>

int flushln(FILE *f) {
int ch;

while ((''\n'' != (ch = getc(f))) && (EOF != ch)) continue;
return ch;
}

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>


CBFalconer< cb ******** @ yahoo .comwrites:
CBFalconer <cb********@yahoo.comwrites:

lnatz写道:
lnatz wrote:

>是否有相当于perl命令chomp in C?如果
没有完全相同的命令,我该如何去除
删除\ n在标准结束时?
>Is there an equivalent to the perl command chomp in C? And if
there is no exact equivalent command, how would I go about
removing the "\n" at the end of a stdin?



int flushln(FILE * f){

int ch;


while(( ''\ n''!=(ch = getc(f)))&&(EOF!= ch))继续;

返回ch;

}


int flushln(FILE *f) {
int ch;

while ((''\n'' != (ch = getc(f))) && (EOF != ch)) continue;
return ch;
}



这是一个很有用的功能,但它与Perl'的相似之处并没有任何特殊的相似性。 chomp功能。


-

Keith Thompson(The_Other_Keith) ks ** *@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu / ~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

That''s a useful function, but it''s doesn''t bear any particular
resemblance to Perl''s chomp function.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于相当于perl中的chomp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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