<myprogram> has encountered a problem and needs to close. Why?

Mar 9, 2009 at 7:23pm
Code:
1
2
3
4
5
6
7
8
9
10
11
12
    char* filepath;
    cout<<"What is the name of the Move Pak that you want to import?"<<endl<<"\"_DEFAULT.pak\" is the default one."<<endl;
    cin>>filepath;
    char* final;
    char working_directory[_MAX_PATH];
    GetCurrentPath(working_directory);
    srand((unsigned)time(0)); 
    CIniReader::CIniReader ini;
    strcat(final,working_directory);
    strcat(final,(const char*)"\\");
    strcat(final,(const char*) filepath);
    ini.CIniInit(final);

Why does that happen? I think it is with strcat.
Last edited on Mar 9, 2009 at 8:27pm
Mar 9, 2009 at 9:15pm
PLEASE HELP!
Mar 9, 2009 at 9:46pm
PLEASE!!! I NEED HELP!
Mar 9, 2009 at 9:53pm
char*s are not strings, they're pointers. You cannot strcat or cin to a pointer unless it actually points to something.

use std::string, or learn how to use C-strings properly. Refer here:

http://cplusplus.com/doc/tutorial/ntcs.html

Also, this is not a chatroom. People aren't here 24/7 to be on your every beck and call. If you don't get an answer in an hour or 2, people just might not have seen your post yet. Be patient. Posting several times in all caps just irritates people.
Last edited on Mar 9, 2009 at 9:53pm
Mar 9, 2009 at 10:49pm
Sorry.
I have another problem.
1
2
3
4
5
6
7
8
9
10
11
12
13
    char filepath[128];
    cout<<"What is the name of the Move Pak that you want to import?"<<endl<<"\"_DEFAULT.pak\" is the default one."<<endl;
    cin>>filepath;
    char final[256];
    char working_directory[_MAX_PATH];
    GetCurrentPath(working_directory);
    srand((unsigned)time(0)); 
    CIniReader::CIniReader ini;
    strcat(final,working_directory);
    strcat(final,"\\");
    strcat(final,filepath);
    ini.CIniInit((char*)final);
    cout<<final<<endl;


It is messed up. It has 4 weird characters before the wanted string.
Mar 9, 2009 at 10:57pm
If you are going to use strcat on line 9, you have to initialize the first character of final[] to \0 so the string appears to start empty.
Mar 9, 2009 at 11:26pm
Aaarrrggghh! I'm used to so many different languages! :(

Thanks!
Topic archived. No new replies allowed.