for my program i need to use chdir() to locate to a folder. right now i ust have it as chdir("/home/ty/ncursesgame/files"); and id rather have it look something likechdir("/home/USER/ncursesgame/files"); where it would autofill the user in for the user of that computer or something. can anyone help out? basically it needs to just know whoever the current user is and use that
the first link didnt work for what i wanted. the second one i didnt know what it was taking about. here the code that i need the paths to be changed if anyone can just straight do it for me. thanks!
std::string home = getenv("HOME"); // To recover the user's home directory
std::string gamefiles = home + "/ncursesgame/files"; // because you want to add the extentsion
chdir(gamefiles.c_str());
Because you might not have a environment you should ALWAYS check the return value of getenv();
i was very close to that. i was thinking that i would need make gamefiles = to home + the ncursesgame/files but now i know i was missing out on the quotation marks cuz i kept getting error "ncursesgame not declared" and "files not declared"
thanks! and one other thing. its kinda nooby, but i forgot what header to put for strings... :P
well it might now be the header. i put #include <string> and that should work but its not.
phew i finally got it to work. i had to take out ncurses.h (as this is only the file for opening the terminal and locating to the folder with the ncurses file) and put in iostream and string.h and then instead of using my usual commpile code, i had to jut simplify it to "make STARTGAME" :) lol
so to sum it up, the answer to this question is:
1 2 3 4 5 6 7 8
//headers
#include <iostream>
#include <string.h>
//the three lines to locate to the folder
std::string home = getenv("HOME");
std::string gamefiles = home + "/ncursesgame/files";
chdir(gamefiles.c_str());
thanks SeiZa! now i can upload the first stable version of my game