cannot pass char *** as parameter


Bisla

It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault.

int main(){
    char** fileList;
    int noOfFiles;
    char* path = ".";
    makeList(&fileList, &noOfFiles, path); 
    return 0;
}

void makeList(char ***fileList, int* noOfFiles, char* path){
    struct dirent **fileListTemp;
    *noOfFiles = scandir(path, &fileListTemp, NULL, alphasort);
    int i;
    fileList = malloc(sizeof(char***));
    *fileList = malloc(sizeof(char**));
    printf("total: %d files",*noOfFiles);
    for(i = 0; i < *noOfFiles; i++){
        printf("%s\n",fileListTemp[i] -> d_name);   //works just fine
    }

    *fileList = malloc(*noOfFiles * sizeof(char*));
    for(i=0; i < *noOfFiles; i++){
        //*fileList[i] = fileListTemp[i] -> d_name;   this didn't work either...
        strcpy(*fileList[i], fileListTemp[i]->d_name);
        printf("%s\n", *fileList[i]);
    }
    //fileList = &list;
    return;
}

Segmentation fault always... and no hope of printing out fileList from main()

thumb key

Here you are overwriting the pointer to char** fileList, which could be a problem:

 fileList = malloc(sizeof(char***));

Here you are overwriting a previously allocated pointer, which looks like another problem:

 *fileList = malloc(*noOfFiles * sizeof(char*));

Related


cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

Pass char to method with int parameter

Hussein Zawawi: The output of the following code is 123because substringfrom beginIndex to EndIndex-1. However, I'm surprised how this is understood as 3(int) charhere , since substringthere are two integers. What is the concept behind this? String x = "12345"

Pass char pointer as parameter to function

unlimited This item table prints different permutations of strings. If I declare the string as a char array in main and pass the array name in the printAnagram function it works fine. But if I declare string as char *s="hello" and pass 's' it crashes. Why? #in

Pass char to method with int parameter

Hussein Zawawi: The output of the following code is 123because substringfrom beginIndex to EndIndex-1. However, I'm surprised how this is understood as 3(int) charhere , since substringthere are two integers. What is the concept behind this? String x = "12345"

Pass char pointer as parameter to function

unlimited This item table prints different permutations of strings. If I declare the string as a char array in main and pass the array name in the printAnagram function it works fine. But if I declare string as char *s="hello" and pass 's' it crashes. Why? #in

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

How to pass const char* as parameter of LPCSTR parameter?

Gábor Marschall I want to use this function to call the PlaySoundA function, but the sound file I want to play doesn't open. void AudioClass::playAudio(const char* incomingData, const char* filePath) { char buffer[100]; // <- danger, only storage for 100

Cannot pass char[] to generic method

slow down I wrote a utility class to solve the problem. It takes a generic array and returns all combinations (no duplicates).nCr import java.util.ArrayList; public class fooClass { public static void main(String[] args) { class Utils {

Cannot pass char array to function

Oz123 I'm having a hard time passing charan array to a function: Here is the code found inside a function that calls another function createbitshape: char ans[8]; char bitshp[8]; ... fgets(ans, 10, stdin); createbitshape(random_num, bitshp); printf("bitshp out

Cannot pass char[] to generic method

slow down I wrote a utility class to solve the problem. It takes a generic array and returns all combinations (no duplicates).nCr import java.util.ArrayList; public class fooClass { public static void main(String[] args) { class Utils {

cannot pass string parameter to api

Mehdi Sgh: I created function in spring: @GetMapping("/projets/traitement/{ville}") public ResponseEntity<List<Projet>> getProjectsInTraitement(String ville) { log.debug("REST request to get a page of Projets"); List<Projet> page = projetRe

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

Cannot pass search term as parameter

Eli I want to display some data in a dropdown list and implement autocomplete. To do this, I use select2a jQuery plugin. My problem is that the search term written in the search box is not being passed as a parameter to my method in the controller. Here is my

cannot pass string parameter to api

Mehdi Sgh: I created function in spring: @GetMapping("/projets/traitement/{ville}") public ResponseEntity<List<Projet>> getProjectsInTraitement(String ville) { log.debug("REST request to get a page of Projets"); List<Projet> page = projetRe

Cannot pass class as parameter to command

Kitten I'm new to programming and I have my pass class that I created with difficulty <Window.Resources>as XAMLa parameter to a command. <Window.Resources> <local:RegisterWindowViewModel x:Key="RegViewModel"/> <local:RegisterValidationConverter x

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_