You are here:

C/how to store files names of a folder in an array

Advertisement


Question
hello,
i want to store all the files names which are present in a folder in an array.please tell me as soon as possible.i have to do my case study.

Answer
Hi dear Mohammad !

Here im presenting you a simple code example Sure it will help you out !


#include <stdio.h>
#include <dir.h>

void main(void)
{
  struct ffblk finfo;
  char array[100][20]; /* array to store 100 file names */
  int done;
  int counter = 0 , i;
  clrscr();
  printf("File names stored in the array:\n");
  done = findfirst("*.*",&finfo,0);
  while (!done)
  {
     strcpy(array[counter++] , finfo.ff_name);
     done = findnext(&finfo);
  }
  for(i = 0; i < counter ; i++)
  printf("%s\n" ,array[i]);
  getch();
}

Note : This program compiled and tested in turbo C/C++

If you found any difficulties in understanding this code please revert back the issues

Thanks and Regards!
Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.