Simple file handling program

The following c++ program is not producing the desired output. Please help.


//File1.cpp Program to open a file and display its contents on console
// and to calculate its size
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
char readFile(char[]);
void main()
{
clrscr();
char filename[20],ch[100];
cout<<"Enter file name - ";
gets(filename);
for(int i=0;i!='\0';i++)
{
ch[i]=readFile(filename);
cout<<ch[i];
}
getch();
}
char readFile(char fname[20])
{
ifstream fin;
char ch;
fin.open(fname,ios::in);
if(!fin)
{
cout<<"File does not exist";
//exit (1);
}
while(!fin.eof())
{
fin.get(ch);
return ch;
}
}




1. What is the desired output?
2. Use code tags and properly format your code.
3. Where do you think the problem lies? Have you tried any forms of debugging? Even simple output messages to do simple assertions can be very helpful.
Topic archived. No new replies allowed.