Link to home
Start Free TrialLog in
Avatar of yunikon
yunikon

asked on

sorting and listing directory files

directory files are being listed but not in order.  
code;

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

#define      NORMAL            0x00
#define      READONLY            0x01
#define      HIDDEN            0x02
#define      SYSTEM            0x04
#define      VOLLABEL            0x08
#define      DIR            0x10
#define      ARCHIVE            0x20

int comp_Names(const void *, const void *);


main()
{

  struct ffblk fblock;
  char dirname[20];
  int i;

  puts("\nEnter directory name ?\n\n");
  gets(dirname);
  if(findfirst(dirname, &fblock, NORMAL) != 0)  {
      puts("\nERROR, FILE NOT FOUND \n\n");
      return 1;
  }
  qsort(dirname, 10, sizeof(char), comp_Names);    // 10 files are in the directory
  for(i = 1; i <= 10; i++)  {
     printf("\n%30s%10ld%10d%10d\n", fblock.ff_name,fblock.ff_fsize,fblock.ff_fdate,fblock.ff_ftime);
          findnext(&fblock);
  }
  puts("\nEND \n\n");
  getch();
  return 0;

}

int comp_Names(const void *aa, const void *bb)
{

      char *F, *G;
      int ee;

      F = (char *)aa;
      G = (char *)bb;

      if(strcmp(F, G) >  0) ee = 1;
      if(strcmp(F, G) <  0) ee = -1;
      if(strcmp(F, G) == 0) ee = 0;
      return(ee);

}

thanks for helping.
-Y
ASKER CERTIFIED SOLUTION
Avatar of mnashadka
mnashadka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial