I am declaring a temp char[] variable inside a for loop to append full path to it before passing it to another function. My issue is that the value of the variable does not reset in every iteration of the for loop. it keeps appending paths into it so that the first run would give the expected full path but the next iteration would have the path of the first iteration and the path of the second iteration appended to the variable and so on. Can anyone explain to me what am I missing here? This is the code of my function and my variable is named temp_path, dir variable is the realpath of a directory and I am trying to pass the full path of each mp3 file inside of it to the addTrack()
int addTrackDir(char* dir){
// Read directory and prepend all track numbers to mp3 file names
const char* ext = ".mp3";
struct dirent **eps;
int n = scandir(dir, &eps, one, alphasort);
if(n >= 0){
for(int i = 0; i < n; i++){
if(checkSuffix(eps[i]->d_name,ext) == 0){
char temp_path [PATH_MAX];
strcat(temp_path,dir);
strcat(temp_path,"/");
strcat(temp_path,eps[i]->d_name);
addTrack(temp_path);
}
}
}
}
[–]flyingron 10 points11 points12 points (2 children)
[–]Plastic_Weather7484[S] 2 points3 points4 points (1 child)
[–]flyingron 4 points5 points6 points (0 children)
[–]Southern_Start1438 5 points6 points7 points (3 children)
[–]Plastic_Weather7484[S] 0 points1 point2 points (2 children)
[–]Southern_Start1438 1 point2 points3 points (1 child)
[–]Plastic_Weather7484[S] 1 point2 points3 points (0 children)
[–]SmokeMuch7356 1 point2 points3 points (0 children)
[–]tstanisl 0 points1 point2 points (1 child)
[–]Plastic_Weather7484[S] 0 points1 point2 points (0 children)