|
-
Mar 3rd, 2001, 03:29 PM
#1
Thread Starter
Hyperactive Member
In this code used to read the contents of a text file I get a illegal operation at the very end right. Here the code
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
FILE *fp;
class myclass{
public:
void openfile(char *path);
};
int main()
{
char retval;
myclass s;
cout <<"Enter a path to open \n";
cin.getline(&retval, 30, '\n');
s.openfile(&retval);
system("pause");
return 0;
}
void myclass: penfile(char *path)
{
char ch;
if((fp = fopen(path, "r")) ==NULL)
cout << "Cannot open file ERROR";
ch = getc(fp);
while (ch!=EOF){
putchar(ch);
ch = getc(fp);
}
fclose(fp);
}
*How do I embed code in a post? Thanks for your help.
Matt 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|