如何删除文件中的字符? [英] how to delete a character in a file ?

查看:75
本文介绍了如何删除文件中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我目前正在开发一种工具,用于在linux,

windows和mac之间转换文本文件。


一行的结尾由windows中的2个字符编码,而且只有一个在

unix&苹果电脑。所以我必须在一行的每一端删除一个字符。


car = fgetc(myFile);

while(car!= EOF){

if(car == 13){

car2 = fgetc(myFile);

if(car2 == 10){

// 2个字符的fseek

//删除字符

//覆盖第二个字符

}

}

}


我该怎么办?有没有我可以使用的功能?我在stdio.h中找不到

一个


提前,


Jerem。

Hi all,

I''m currently developping a tool to convert texts files between linux,
windows and mac.

the end of a line is coded by 2 characters in windows, and only one in
unix & mac. So I have to delete a character at each end of a line.

car = fgetc(myFile);
while (car != EOF) {
if (car == 13) {
car2 = fgetc(myFile) ;
if (car2 == 10) {
// fseek of 2 characters
// delete a caracter
// overwrite the second caracter
}
}
}

how can I do that ? is there a function that I can use ? I can''t find
one in stdio.h

thx in advance,

Jerem.

推荐答案

S!mb @< S!mb @ nop>写道:
S!mb@ <S!mb@nop> wrote:
我正在开发一种工具来转换linux,
windows和mac之间的文本文件。
一行的结尾由windows中的2个字符编码,而
unix&中只有一个。苹果电脑。所以我必须在一行的每一端删除一个字符。
car = fgetc(myFile);
while(car!= EOF){
if(car == 13){


更好用' '\'''而不是一些魔术价值。

car2 = fgetc(myFile);
if(car2 == 10){


那将是''\ n ''。顺便说一句,当你以文本模式打开文件

时,你可能永远不会看到 ''\ r''和''\ n''作为两个单独的字符

如果\\\\ n组合是系统中的行尾标记。

// 2个字符的fseek
//删除字符
//覆盖第二个字符
怎么能我这样做?有没有我可以使用的功能?我在stdio.h中找不到
一个
I''m currently developping a tool to convert texts files between linux,
windows and mac. the end of a line is coded by 2 characters in windows, and only one in
unix & mac. So I have to delete a character at each end of a line. car = fgetc(myFile);
while (car != EOF) {
if (car == 13) {
Better use ''\r'' instead of some "magic" values.
car2 = fgetc(myFile) ;
if (car2 == 10) {
And that would be ''\n''. BTW, when you open the file in text mode
you may never "see" the ''\r'' and ''\n'' as two separate characters
if the "\r\n" combination is the end of line marker on the system.
// fseek of 2 characters
// delete a caracter
// overwrite the second caracter how can I do that ? is there a function that I can use ? I can''t find
one in stdio.h




参见FAQ,第19.14节。简而言之,你不能从文件中间删除

中的东西,你必须复制除了你的东西之外的所有东西。

不想要一个新的东西文件。

问候,Jens

-

\ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de

\ __________________________ http://www.toerring.de


在文章< 2m ************ @ uni-berlin.de>中, Je *********** @ physik.fu-berlin.de

写道:
In article <2m************@uni-berlin.de>, Je***********@physik.fu-berlin.de
wrote:
S!mb @< S!mb @ nop>写道:
S!mb@ <S!mb@nop> wrote:
我正在开发一种工具,用于在linux,
windows和mac之间转换文本文件。
I''m currently developping a tool to convert texts files between linux,
windows and mac.


(..)


(..)

if(car == 13){
if (car == 13) {



更好地使用''\ r''而不是某些魔术价值。



Better use ''\r'' instead of some "magic" values.




对于传统的MacOS编译器,''\ r''往往是10,

和''\ n' '往往是13.这说明当使用非原生格式的二进制文件处理

时,最好使用魔法

值。 OTOH,当与本地文本文件签约时,''\ n''当然是

最佳。

Fran?ois Grieu



For traditional MacOS compilers, ''\r'' tends to be 10,
and ''\n'' tends to be 13. This illustrates that when dealing
with binary files in a non-native format, it is best to use magic
values. OTOH, when dealign with local text files, ''\n'' is
best, of course.
Fran?ois Grieu




" S!mb @" < S MB @ NOP>!;在消息中写道

news:40 *********************** @ news.free.fr ...

"S!mb@" <S!mb@nop> wrote in message
news:40***********************@news.free.fr...
大家好,

我正在开发一种工具,用于在linux,
windows和mac之间转换文本文件。

结束行在窗口中由2个字符编码,并且只有一个在
unix&苹果电脑。所以我必须在一行的每一端删除一个字符。

car = fgetc(myFile);
while(car!= EOF){
if(car == 13){
car2 = fgetc(myFile);
if(car2 == 10){
// fseek of 2 characters
//删除字符
/ /覆盖第二个特征
}
}
}
我怎么能这样做?有没有我可以使用的功能?我不能在stdio.h中找到一个

提前,

Jerem。
Hi all,

I''m currently developping a tool to convert texts files between linux,
windows and mac.

the end of a line is coded by 2 characters in windows, and only one in
unix & mac. So I have to delete a character at each end of a line.

car = fgetc(myFile);
while (car != EOF) {
if (car == 13) {
car2 = fgetc(myFile) ;
if (car2 == 10) {
// fseek of 2 characters
// delete a caracter
// overwrite the second caracter
}
}
}

how can I do that ? is there a function that I can use ? I can''t find
one in stdio.h

thx in advance,

Jerem.




嗯,已经有一个工具,dos2unix,反之亦然。为什么要重新发明

轮。想一些新的东西。


-

获奖者不做不同的事情,他们做的事情不同。


Madhur Ahuja

印度


主页: http://madhur.netfirms.com

电子邮件:madhur< underscore> ahuja< at> yahoo< dot> com



Well, there is already a tool, dos2unix and vice versa. Why reinvent the
wheel. Think something new.

--
Winners dont do different things, they do things differently.

Madhur Ahuja
India

Homepage : http://madhur.netfirms.com
Email : madhur<underscore>ahuja<at>yahoo<dot>com


这篇关于如何删除文件中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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