whackaxe
03-24-2004, 09:43 PM
hi peeps
i'm currently writing a small program that has a file system class (called C_fsystem)
this is it's code
[CODE]
class C_fsystem
{
protected:
char SZ_fpath [];
char SZ_fname [];
char SZ_fexten [];
public:
void setPath(char* TMP_buffer){strcpy(SZ_fpath, TMP_buffer);}
void setName(char* TMP_buffer){strcpy(SZ_fname, TMP_buffer);}
void setExten(char* TMP_buffer){strcpy(SZ_fexten, TMP_buffer);}
char fullName();
C_fsystem(char*, char*, char*);
};
C_fsystem::C_fsystem(char* PARAM_path, char* PARAM_name, char* PARAM_exten)
{
strcpy(SZ_fpath, PARAM_path);
strcpy(SZ_fpath, PARAM_name);
strcpy(SZ_fpath, PARAM_exten);
}
char C_fsystem::fullName()
{
char TMP_path [1000];
strcpy(TMP_path, SZ_fpath);
strcat(TMP_path, SZ_fname);
strcat(TMP_path, ".");
strcat(TMP_path, SZ_fexten);
}
int main()
{
C_fsystem myfile("D:\\my documents 2\\robin\\cpp sources\\terraserve\\", "main", "cpp");
cout<<myfile.fullName();
cin.get();
exit(0);
}
[CODE]
now everything compiles well, but i get a wierd symbol on my screen instead of the path, like i was expecting.
i'm getting the impression ive got compeltly the wrong end of the stick concerning strings.
another problem is, how do i initalise strings/char arrays so they can be any length? do i have to use dynamic memeory or not?
i'm currently writing a small program that has a file system class (called C_fsystem)
this is it's code
[CODE]
class C_fsystem
{
protected:
char SZ_fpath [];
char SZ_fname [];
char SZ_fexten [];
public:
void setPath(char* TMP_buffer){strcpy(SZ_fpath, TMP_buffer);}
void setName(char* TMP_buffer){strcpy(SZ_fname, TMP_buffer);}
void setExten(char* TMP_buffer){strcpy(SZ_fexten, TMP_buffer);}
char fullName();
C_fsystem(char*, char*, char*);
};
C_fsystem::C_fsystem(char* PARAM_path, char* PARAM_name, char* PARAM_exten)
{
strcpy(SZ_fpath, PARAM_path);
strcpy(SZ_fpath, PARAM_name);
strcpy(SZ_fpath, PARAM_exten);
}
char C_fsystem::fullName()
{
char TMP_path [1000];
strcpy(TMP_path, SZ_fpath);
strcat(TMP_path, SZ_fname);
strcat(TMP_path, ".");
strcat(TMP_path, SZ_fexten);
}
int main()
{
C_fsystem myfile("D:\\my documents 2\\robin\\cpp sources\\terraserve\\", "main", "cpp");
cout<<myfile.fullName();
cin.get();
exit(0);
}
[CODE]
now everything compiles well, but i get a wierd symbol on my screen instead of the path, like i was expecting.
i'm getting the impression ive got compeltly the wrong end of the stick concerning strings.
another problem is, how do i initalise strings/char arrays so they can be any length? do i have to use dynamic memeory or not?