File Searching Problem

This is a discussion on File Searching Problem within the C Programming forums, part of the General Programming Boards category; have been working on this for a while now as I learn new things. This has kinda been my little ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    99

    File Searching Problem

    have been working on this for a while now as I learn new things. This has kinda been my little project that I wanted to do alone for pride I suppose but I am getting so frustrated with it. When I run the program and search for a file in that same directory it will find the first file and it will spit an error out at me. Secondly if I try to search for a file in a sub directory it skips over it and tells me the search is completed without returning a file that I know is there. I believe that I am going about things in a wrong way in logic. I just got the Borland compiler where the find functions are different than in DevC++. Any help is greatly appreciated.

    Code:
    //Basic for right now
    #include<dir.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #define MAX 256
    struct ffblk find;
    
    main(int argc, char *argv[]){
    int done;
    char dir[MAX];
    char *fin="Search completed\n";
    
    if (argc<2){
        printf("Usage: FIND <filename>\n");
        exit(1);
        }
    done = findfirst( argv[1], &find, FA_NORMAL);
    while (done != EOF){
        int x=1,cd_done;
    
        getcwd( dir, MAX);
        strcat(dir,"\\");
        strcat(dir, find.ff_name);  //Attach forward slash to end of dir name
        printf("%d)  %s\n",x,dir);
        if (find.ff_attrib == (FA_DIREC || _A_SUBDIR)) //check for directories in specified dir
        {
            chdir(find.ff_name);
            cd_done = findfirst(argv[1],&find,FA_NORMAL);
    	if (cd_done == (-1))
    	     printf("No files in %s\n",find.ff_name);
    	else
    	{
                 while (cd_done != EOF)
                 {
                     getcwd( dir, MAX);
                     strcat(dir, find.ff_name);
                     printf("%d)  %s\n",x,dir);
                     cd_done = findnext(&find);
                 }
    	}
        }
        else
            ;
        done = findnext(&find);
    }
    findclose(&find);
    puts(fin);
    return 0;
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Enjoy.
    Attached Files Attached Files
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 12:39 PM
  2. Problem with file and array
    By paok in forum C Programming
    Replies: 5
    Last Post: 05-01-2008, 05:19 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21