Solved

HOW TO INSERT STRING INTO TOP OF FILE?

Posted on 1998-09-08
4
190 Views
Last Modified: 2010-04-15
HOW TO INSERT STRING INTO TOP OF FILE?(EXAMPLE CODE)
0
Comment
Question by:tanad
4 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 20 total points
ID: 1252552
Due to the workings of most file systems insertions to a file are impossible.
You should create a new file, write the string to it, append the old file to the new, delete the old and rename the new.
0
 
LVL 1

Expert Comment

by:jkrautner
ID: 1252553
Well, I think you have only 2 choices.
1. Write your string in a new file, and then also programmaticaly
   read the old file and write every record into the new file.
or
2. Write your string in a new file, and now spawn a DOS copy
   to append both files together.
   i.e. system("copy string.txt+oldfile.txt new.txt");
 

I think the easiest way is to write your string into a file
and then spawn the copy command to append the old file to
the file
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1252554
It is always helpful to say what operating system you are using.
If you are using UNIX you don't need to use C:

echo "string" > newfile
cat oldfile >> newfile
mv newfile oldfile

This writes the string to the top of a new file and then concatenates the original file to the end of the new file. Finally it renames the new file to have the same name as the original file.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 1252555
actually if you are using dos you can do the same thing as unix, just:
echo "string" >newfile
type oldfile >>newfile
move /y newfile oldfile
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adjust Mfcapp 29 166
C simple state machine for client server handshake 4 299
Problem to ASCII 1 176
Why  my code (program) build with old compiler? 11 38
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question