Thread: Scanning a directory

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Scanning a directory

    just by looking at this code can anyone see why it crashes my program each time? it does what its suppose to then when i gets to the last file it crashes.
    Code:
                  char *Buffer;
                  char *path = "C:\\windows";
                  char *type = "*.*";
                  SetCurrentDirectory(path);
                  struct ffblk ffblk;
                  int done;
                  done = findfirst(type,&ffblk,0);
                  while (!done)
                  {
                    char buff[1024];
                    sprintf(buff,"%s\r\n", ffblk.ff_name);
                    done = findnext(&ffblk);
                  }

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    All pointers to string literals should be const char *, but that can't be causing the crash...

    A crash cause could be that a filename just might be longer than 1021 characters - unlikely, but possible.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  3. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  4. Scanning a directory on ftp
    By pinkcheese in forum Windows Programming
    Replies: 7
    Last Post: 10-13-2002, 12:01 PM
  5. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 09:43 AM