English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm trying to help my friend out with this and we cant get it working. How would you go about doing this?

1. Write a C program that opens two data files one for reading and another for
writing. The program must copy the contents of input data file to output file
with the data double line spaced. Example below. The program must work
for all data files [ and not just for the following example ]

Input file:

Earth is Solid
So is Moon.

Output File:

Earth is Solid

So is Moon.

2007-08-01 04:59:09 · 3 answers · asked by ? 2 in Computers & Internet Programming & Design

3 answers

If ur talkin bout c++ then its here:

#include
#include
#include
class handle2files
{
public:
readnWrite();
};
void handle2files::readnWrite()
{
ifstream inputfile;
inputfile.open("filename.ext");
ofstream outputfile;
outputfile.open("filename.ext",ios",ios::app);
char ch[300]; //to temporarily store each char from input file
while(inputfile)
{
inputfile.get(ch[i]);
if(ch[i]=='\n') signal=-1; //one line read
cout< if(signal==-1)
{
ch[++i]='\n'; //this is to add one more line gap(doubled gap)
outputfile.write(ch,sizeOf(ch)); //line written into output file
signal=0; i=0;

}
}
inputfile.close();
outputfile.close();
//done!
}

void main()
{
handle2files object;
object.readnWrite();
getch();
}

2007-08-01 06:04:09 · answer #1 · answered by Swapnil B 2 · 0 0

Open the input file for read
Read the first record
If end-of-file
print error message
end-if
Open the output file or write

Loop until end-of-file
output = input + '\n\n'
write output file
read input file
end-loop

Close input file
Close output file

That should do it.

2007-08-01 12:23:47 · answer #2 · answered by AnalProgrammer 7 · 0 0

Computer Tutorials, Interview Question And Answer
http://freshbloger.com/

2007-08-01 13:26:58 · answer #3 · answered by aerokan a 3 · 0 0

fedest.com, questions and answers