Click here to Skip to main content
15,918,007 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ODS_SELECTED Pin
Jochen Arndt22-May-14 0:19
professionalJochen Arndt22-May-14 0:19 
QuestionHow To Decrease Video Size Pin
AmbiguousName21-May-14 20:37
AmbiguousName21-May-14 20:37 
AnswerRe: How To Decrease Video Size Pin
SoMad21-May-14 23:25
professionalSoMad21-May-14 23:25 
AnswerRe: How To Decrease Video Size Pin
AmbiguousName22-May-14 1:06
AmbiguousName22-May-14 1:06 
GeneralRe: How To Decrease Video Size Pin
SoMad22-May-14 15:12
professionalSoMad22-May-14 15:12 
AnswerEncode it as an MP4 File Pin
Software_Developer22-May-14 1:49
Software_Developer22-May-14 1:49 
QuestionI need a two level priority queue Pin
Member 1042711521-May-14 19:24
Member 1042711521-May-14 19:24 
AnswerRe: I need a two level priority queue Pin
«_Superman_»21-May-14 19:53
professional«_Superman_»21-May-14 19:53 
GeneralMessage Closed Pin
21-May-14 19:59
Member 1042711521-May-14 19:59 
GeneralRe: I need a two level priority queue Pin
«_Superman_»21-May-14 20:45
professional«_Superman_»21-May-14 20:45 
GeneralMessage Closed Pin
21-May-14 20:49
Member 1042711521-May-14 20:49 
GeneralRe: I need a two level priority queue Pin
«_Superman_»21-May-14 21:33
professional«_Superman_»21-May-14 21:33 
GeneralRe: I need a two level priority queue Pin
Member 1042711521-May-14 21:49
Member 1042711521-May-14 21:49 
GeneralRe: I need a two level priority queue Pin
Member 1042711521-May-14 21:54
Member 1042711521-May-14 21:54 
QuestionHow to use c + + and web interaction Pin
jingjing yuan21-May-14 3:20
jingjing yuan21-May-14 3:20 
SuggestionRe: How to use c + + and web interaction Pin
Richard MacCutchan21-May-14 21:54
mveRichard MacCutchan21-May-14 21:54 
QuestionC program for Embedded controller ICP CON I7188XAD Pin
Member 1083123320-May-14 0:03
Member 1083123320-May-14 0:03 
AnswerRe: C program for Embedded controller ICP CON I7188XAD Pin
CPallini20-May-14 0:47
mveCPallini20-May-14 0:47 
AnswerRe: C program for Embedded controller ICP CON I7188XAD Pin
leon de boer20-May-14 3:22
leon de boer20-May-14 3:22 
GeneralRe: C program for Embedded controller ICP CON I7188XAD Pin
Randor 20-May-14 13:00
professional Randor 20-May-14 13:00 
Question[C]Strings' array goes crazy. Pin
militandri19-May-14 1:29
militandri19-May-14 1:29 
Hi everyone.
I wrote a function that should copy in a strings' array all the name of several files contained in a folder.
C++
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;i<n_files;i++){
		dird=readdir(sd);
		filenames[i]=dird->d_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:
C++
...
filenames = malloc(n_files * sizeof(char));
    for(i=0;i<n_files;i++){
	filenames[i] = malloc(20 * sizeof(char));
    }
...

AnswerRe: [C]Strings' array goes crazy. Pin
Freak3019-May-14 2:04
Freak3019-May-14 2:04 
AnswerRe: [C]Strings' array goes crazy. Pin
enhzflep19-May-14 2:16
enhzflep19-May-14 2:16 
GeneralRe: [C]Strings' array goes crazy. Pin
militandri19-May-14 2:57
militandri19-May-14 2:57 
GeneralRe: [C]Strings' array goes crazy. Pin
enhzflep19-May-14 3:06
enhzflep19-May-14 3:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.