Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
Question[IFileIsInUse] : Need help with its implementation Pin
Mohsin Munawar18-May-14 18:23
Mohsin Munawar18-May-14 18:23 
AnswerRe: [IFileIsInUse] : Need help with its implementation Pin
Richard MacCutchan18-May-14 21:33
mveRichard MacCutchan18-May-14 21:33 
QuestionCreate style element with c++ Pin
vutrulavotann17-May-14 1:11
vutrulavotann17-May-14 1:11 
QuestionLZMA SDK and .zip files Pin
John Malcosky16-May-14 4:25
John Malcosky16-May-14 4:25 
SuggestionRe: LZMA SDK and .zip files Pin
Code-o-mat16-May-14 6:26
Code-o-mat16-May-14 6:26 
GeneralRe: LZMA SDK and .zip files Pin
John Malcosky16-May-14 8:13
John Malcosky16-May-14 8:13 
AnswerRe: LZMA SDK and .zip files Pin
Graham Breach16-May-14 8:46
Graham Breach16-May-14 8:46 
GeneralRe: LZMA SDK and .zip files Pin
John Malcosky16-May-14 9:24
John Malcosky16-May-14 9:24 
AnswerRe: LZMA SDK and .zip files Pin
leon de boer16-May-14 19:00
leon de boer16-May-14 19:00 
QuestionDouble buffering Pin
imran.prdc14-May-14 20:58
imran.prdc14-May-14 20:58 
QuestionRe: Double buffering Pin
CPallini14-May-14 21:39
mveCPallini14-May-14 21:39 
AnswerRe: Double buffering Pin
Legor14-May-14 21:54
Legor14-May-14 21:54 
AnswerRe: Double buffering Pin
Richard MacCutchan14-May-14 21:56
mveRichard MacCutchan14-May-14 21:56 

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.