Sunday, August 2, 2009

C programming: how would i go about this question:?

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.

C programming: how would i go about this question:?
If ur talkin bout c++ then its here:





#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;fstream.h%26gt;


class handle2files


{


public:


readnWrite();


};


void handle2files::readnWrite()


{


ifstream inputfile;


inputfile.open("filename.ext");


ofstream outputfile;


outputfile.open("filename.ext",ios",io...


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%26lt;%26lt;ch;


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();


}
Reply: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.
Reply:Computer Tutorials, Interview Question And Answer


http://freshbloger.com/


No comments:

Post a Comment