Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: ink on February 12, 2006, 04:02:34 PM

Title: [C/C++] FindFile function...issues
Post by: ink on February 12, 2006, 04:02:34 PM
This is a sample code from MSDN for the findfile function that I edited a little (probably messed it up since I dont know squat about c) but yeah, im looking for guidence/direction



#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <stdio.h>

int main()
{
char findFile [80];
WIN32_FIND_DATA FindFileData;
HANDLE hFind;

printf ("Enter file to find: ");
scanf ("%s",findFile);

hFind = FindFirstFile(findFile, &FindFileData);

if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid File Handle. GetLastError reports %d\n",
GetLastError ());
return (0);
}
else
{
printf ("The first file found is %x\n",
FindFileData.cFileName);
FindClose(hFind);
return (1);
}
}




Problem I'm having at the moment is that it either returns saying its an invalid handle or that "The first file found is 12fe1c" everytime  ???
Title: Re: [C/C++] FindFile function...issues
Post by: zorm on February 12, 2006, 04:05:11 PM
It totally helps if you give a problem or something that you are having.
Title: Re: [C/C++] FindFile function...issues
Post by: ink on February 12, 2006, 04:07:58 PM
Scratch that problem, I had to change  the %x to %s
which brings up another question, what do %d, %s, and %x represent?


Um... scratch that question as well, and incase anybody else didn't know:
%d returns decimal value, %x returns hex value and %s returns string value, I think?
Title: Re: [C/C++] FindFile function...issues
Post by: Sidoh on February 12, 2006, 04:13:15 PM
Step one: http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&rls=GGGL,GGGL:2005-09,GGGL:en&q=printf
Step two: http://www.cplusplus.com/ref/cstdio/printf.html

;)

%d is a signed integer. %s is a string, %x is an unsigned hex integer.