files

This is a discussion on files within the C Programming forums, part of the General Programming Boards category; Hi! This is a snippet from my code and what am I trying to do is that the file the ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question files

    Hi!

    This is a snippet from my code and what am I trying to do is that the file the program reads from some selected directory extends it's length to 12 in that way that adds spaces at the end of the filename.
    Example:
    "level.lvl"
    "level.lvl..."

    Note: . is space

    The problem is that not all files get extended (especially the ones that has shorter filename than the file before). WHY, I don't know, so please help me.

    Code:
    short SearchFileLoop = 1, MatchFound = 0;
    struct _finddata_t File = {0};
    intptr_t Search = 0, FoundedFiles = 0;
    .
    .
    .
    if ((FoundedFiles = _findfirst ("./DATA/", &File)) != -1)
    {
    	while (SearchFileLoop)
    	{
    		for (i = 0; i < 12; i++)
    		{
    			if (File.name[i] == '\0') File.name[i] = ' ';
    		}
    		// matching file founded
    		if (strcmpi ("level.lvl   ", File.name) == 0) MatchFound = 1;
    		Search = _findnext (FoundedFiles, &File);
    		if (Search == -1) SearchFileLoop = 0;
    	}
    }
    .
    .
    .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Jo! Thanks for your reply and it is working now. But you know, another solution for this problem is this too:
    Code:
    if (File.name[i] == '\0')
    {
        File.name[i]     = ' ';
        File.name[i+1] = '\0';
    }
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM

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