| | |
Emptying char MAX_PATH array?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 45
Reputation:
Solved Threads: 1
This is a very simple problem, but for some reason I can't get it to work. I need to empty a variable ( char fileName[MAX_PATH] =""; ).
It needs to be to where when I use this that it sees if it equals "", this wont work if it equals NULL will it?:
How could I do this? I have tried:
Those all return errors, why can't I empty the variable?
It needs to be to where when I use this that it sees if it equals "", this wont work if it equals NULL will it?:
CPP Syntax (Toggle Plain Text)
if (fileName = "") { }
How could I do this? I have tried:
CPP Syntax (Toggle Plain Text)
fileName = ""; fileName = NULL; fileName[MAX_PATH] = "";
Those all return errors, why can't I empty the variable?
Last edited by killdude69; May 31st, 2009 at 2:33 am.
Keep it simple:
C++ Syntax (Toggle Plain Text)
fileName[0] = '\0'; // or even *fileName = 0; // to test: if (*fileName) { // non-empty
•
•
•
•
How would I test if it IS empty.
Because I am currently using: if (fileName == "")
And I am using this for over 6 if statments.
C++ Syntax (Toggle Plain Text)
if (!*fileName) // or if (fileName[0] == '\0') // or if (strlen(fileName) == 0)
fileName == "" is equal to false in all cases. Why? Think about pointers comparison
![]() |
Similar Threads
- char** for string array problem (C)
- convert char** (c string array) to std::string[] (C++)
- shift (bitshift) through char array (C++)
- char pointer and array issues (C++)
- fstream to char and int array (C++)
Other Threads in the C++ Forum
- Previous Thread: Is it illegal to compare NULL pointers?
- Next Thread: Unexplained INVALID_HANDLE_VALUE from CreateFile()
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






