Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HOW TO INSERT STRING INTO TOP OF FILE?

Posted on 1998-09-08
4
Medium Priority
?
219 Views
Last Modified: 2010-04-15
HOW TO INSERT STRING INTO TOP OF FILE?(EXAMPLE CODE)
0
Comment
Question by:tanad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 60 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

610 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