Hi. Can anyone tell me what the problem with this function is? It basically takes a file path, searches for the file name in it. It *should* return a pointer to the first character of the string (the file name). Here it is:
it gives me the following warning:Code:/* returns pointer to file name from file path. */ char * fileName(const char * filePath) { int i, j; char fileName[FILENAME_MAX+1]; for (i = strlen(filePath), j=0 ; i > 0; i--, j++) { if (filePath[i] == '\\') break; fileName[j] = filePath[i]; } return fileName; }
c:\abdallah\file encrypter (everything)\file encrypter vs\file encrypter\file encrypter\fileextension.c(74) : warning C4172: returning address of local variable or temporary.
When I try to output it using printf like this:
it doesn't output anything.Code:printf("%s", fileName(filename));
can anyone help me out?



LinkBack URL
About LinkBacks




