Dear there,
I wrote a simple all->unix ascii file converter on fly, see the comments below. I am using temp=tmpfile() to hold contents for later processing, but it seems lost later on. -
/* FILE* file is assigned before calling this routing.
-
After calling this routine, 'file; is supposed to point to the temporary file stream
-
with processed content. However, I found later that file has no content at all.
-
*/
-
-
/**
-
* simple text convert: convert all to Unix line ending
-
* I use fgets() to read a line, which stops whenever \n (LF) is met. However, different line ending could be used:
-
* DOS/Windows: CR LF
-
* Unix: LF
-
* MAC OS X: LF
-
* MAC (prior to MAC OS X): CR
-
* this convert is simple since it is only for use with fgets(), strtok(), and strtof()
-
* strtok() will skip leading 'sep' when processing tokens, in this file sep=' \t,'; strtof() will
-
* skip leading white space as specified by isspace(). Hence I replace CR LF with LF SPACE; and CR with LF.
-
*/
-
void trimcarriage(){
-
FILE* temp=tmpfile();//see p483 k.n.king
-
int ch, chnext;
-
while(ch=getc(file) != EOF){
-
if (ch != '\r'){//straight copy
-
putc(ch, temp);
-
}else{
-
putc('\n',temp);//replace it with \n
-
if (chnext=getc(file) != '\n'){
-
ungetc(chnext, file);//put it (including EOF) back
-
}//otherwise '\n' is not wrote into temp
-
}
-
}
-
fclose(file);
-
rewind(temp);
-
file=temp;
-
}
-
2 1494
Are temp and file both FILE* to the same file?
If so, you have a problem because you cannot have two active FILE* to the same file.
I found the mistake in the statement:
ch=getc(file) != EOF
which should be
(ch=getc(file)) != EOF
due to operator precedence.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jason Heyes |
last post by:
I would like to modify the contents of a file, replacing all occurances of
one string with another. I wrote these functions:
bool read_file(std::string name, std::string &s);
bool write_file(std::string name, const std::string &s);
void find_replace(std::string &s, std::string first, std::string second);
bool find_replace_file(std::string name, std::string first, std::string
second)
{
|
by: Christopher Benson-Manica |
last post by:
Is there a way to get the entire contents of the current document as a
string? I want to send the document contents to a markup validation
service.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
|
by: Paul T. Rong |
last post by:
Hi everybody,
This time a very very difficult case:
I have a table "tblStudent", there are 50 students, I also made a form
"frmStudent" based on "tblStudent", now if I don't want to show all the
students in a classical (vertically, from top to bottom) way, but make them
"sitting" in 50 text boxes, 5 rows 10 columns, how to do it?
Thanks in advance.
|
by: Pilocarpine |
last post by:
Hi,
It's been a while since I posted but good ol' google groups is
confusing me these days and not giving me nice answers.
I have this field in a table with some data
HI1
HI2
HI1
|
by: Junkguy |
last post by:
I need some help programmatically causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).
My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on...
| |
by: DotNetJunky |
last post by:
I have built a control that runs an on-line help system. Depending on the
category you selected via dropdownlist, it goes out and gets the child
subcategories, and if there are any, adds a new dropdownlist to the screen
for selection. This continues until there are no children, and then it
checks for a help article list based on that last selection and displays
actual articles for display.
Adding the controls and getting everything...
|
by: Fraggle |
last post by:
I have a repeater with controls added at run time. the <template> also
contains a <asp:textbox that is made visible on some repeater
elements.
when I come to read the text info out it has disapeared. The read is
done on a button click.
I can read the selected items from the other controls in the repeater,
demo page here
|
by: Russell Warren |
last post by:
I've got a case where I'm seeing text files that are either all null
characters, or are trailed with nulls due to interrupted file access
resulting from an electrical power interruption on the WinXP pc.
In tracking it down, it seems that what is being interrupted is either
os.remove(), or os.rename(). Has anyone seen this behaviour, or have
any clue what is going on?
On first pass I would think that both of those calls are single step...
|
by: google |
last post by:
Hi,
I'm using Python with pygtk and have this problem - I have read the
contents of a file into the text buffer with this code,
infile = open("mytextfile", "r")
if infile:
string = infile.read()
infile.close()
textbuffer.set_text(string)
|
by: devnew |
last post by:
hi
i am trying to create a cache of digitized values of around 100
image files in a folder..In my program i would like to know from time
to time if a new image has been added or removed from the folder..
one scheme suggested was to create a string from the names of sorted
image files and give it as the cache name..
ie ,if i have one.jpg,three.jpg,new.jpg ,
i will name the cache as 'newonethree.cache' and everytime i want to
check...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |