Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
M

militandri

@militandri
About
Posts
2
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • [C]Strings' array goes crazy.
    M militandri

    Thank you for the answer. Of course I declared filenames as char**... :cool: But I didn't know really good how the d_name variable works, then I made some mistakes... Now it's all clearer!

    C / C++ / MFC data-structures

  • [C]Strings' array goes crazy.
    M militandri

    Hi everyone. I wrote a function that should copy in a strings' array all the name of several files contained in a folder.

    void get_filenames(char dir[]){
    int i=0;
    DIR *sd;

    sd = opendir(dir);
    struct dirent \*dird;
    
    printf("\\nLa cartella %s contiene %d files.", dir, n\_files);    //"Folder %s contains %d files."
    	
    seekdir(sd, 2);
    
    for(i=0;id\_name;
    	printf("\\n%s", filenames\[i\]);
    }
    
    closedir(sd);
    

    }

    When I call this function it seems to be alright, and the printf contained in the for cicle prints the names of files correctly... But if I try to print these names somewhere out of this function, I see that each string of filenames[] contains the last string printed in the get_filenames function, that is the last file in the folder. I allocated filenames[] in another void function, this way:

    ...
    filenames = malloc(n_files * sizeof(char));
    for(i=0;i

    C / C++ / MFC data-structures
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups