Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-02-2002, 06:31 PM   #1 (permalink)
Blaqb0x
Registered User
 
Blaqb0x's Avatar
 
Join Date: Jun 2002
Posts: 3
Blaqb0x is on a distinguished road
pass filename to function

Hi,
Im trying to pass a file name to a function that will print out the contents of the file.

can any one see what's going wrong?

ERROR:
prac $> g++ readfileprac_function.cxx -o readfile
readfileprac_function.cxx: In function `void PrintFile (char)':
readfileprac_function.cxx:30: no matching function for call to
`fstream::fstream (char &, ios::open_mode)'
/usr/include/g++-3/fstream.h:83: candidates are: fstream::fstream ()
/usr/include/g++-3/fstream.h:84: fstream::fstream (int)
/usr/include/g++-3/fstream.h:86: fstream::fstream
(const char *, int, int = 436)
/usr/include/g++-3/fstream.h:87: fstream::fstream (int,
char *, int)
/usr/include/g++-3/fstream.h:90: fstream::fstream
(const fstream &)

-----------------------------------------------------------
/* This reads a file and putputs
* the the whole file and won't dtop until
* it finds the EOF character
* */

#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>

void PrintFile(char[256]); //prototype for function

int main()
{
char file_name[] = "testfile.dat";

PrintFile(file_name);

return 0;

}


void PrintFile(char FILE_NAME)
{



char ch; //character for holding input characters to be printed
int check_eof; // checks if the EOF is next character


fstream INFILE(FILE_NAME,ios::in);

//check to see if the file was opened correctly
if( !INFILE )
{
cout << "Couldn't open file" <<endl;
exit(1);
}

while( (check_eof = INFILE.peek()) != EOF)
{
INFILE.get(ch);
cout << ch;
}

INFILE.close();


}//end of PrintFile function
--------------------------------------------
Blaqb0x is offline   Reply With Quote
Old 09-02-2002, 10:12 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
redhead is on a distinguished road
Instead of using (char FileName) use (const char* FileName)..

If in doubt, see the prototype for fopen().
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 02:36 AM
Custom function bdl PHP 3 03-07-2003 05:53 PM
is there an alphanumeric php function? sde PHP 2 12-17-2002 02:21 PM
trouble calling auxiliary function in a class brtklt Standard C, C++ 0 07-18-2002 05:22 PM


All times are GMT -8. The time now is 11:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting