FILE *streamname as a public member of a class.
Okaay. At this spring I decided to start learning C++. C I knew somehow before... Now I'm doing a lil proggie to help me with updating my webpages... And I encounter a prob.
I have a class for fileoperations, and it has couple of
FILE *name (Is that variable? stream? I assume you know what I mean... English is not my native language ;) )
Okay, then I have public functions for handling stuff in the files, like one for replacing certain occurances from the file with some txt. Now when I try to read the file with fgets, it crashes my proggie O_o
Compiler does not spot errors, but program crashes on the fgets line.
It is something like that:
class (in header)
Code:
.
.
.
#ifndef _FILEOP_H
#define _FILEOP_H
class fileop {
private:
public:
.
char path[100];
char filename[50];
char wholename[151];
.
FILE *reading,*writing,*creating,*temporary;
.
.
.
};
And in fileop.cpp I have functions
Code:
.
.
.
int fileop::replace(char to_be_replaced[],char replacement[]){
char line[2000],temp[151]; //temp is created later from wholename by changing last letter
.
.
.
reading = fopen(wholename,"r");
//this one works just fine.
.
.
temporary=fopen(temp,"w");
.
fgets(line,1999,reading); //at this point I do receive errormessage :|
.
.
.
I also had problems with checking if the reading was already open (differed from the null) before opening the file. So I just skipped that part.
Is there some dark C/C++ ghost, backstabbing us poor noobs, or is there a real explanation? :D