Function errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile("C:\\*",&file);
    if (search_handle)
    {
        do
        {
            if(file.cFileName == a)
		{CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) ||
		ShellExecute(handle, "find", <fully_qualified_path_to_folder>, //The handle after the ShellExecute is undefined and the '<' which is
// located before the fully_qualified thingy says that it expected an expression.
NULL, NULL, 0)||
ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);


    std::cout << "Found the game you wanted to play!" << std::endl;
}
        while(FindNextFile(search_handle,&file));
        FindClose(search_handle);


This function is supposed to search the computer for a certain file which in my program is file 'a'. There are problems with my function though, and if anyone could give me pointers I would be grateful.
well, file.cFileName contains the 'fully qualified path to folder'.

use _splitpath() to extract the path and filename:

http://msdn.microsoft.com/en-us/library/e737s6tf%28v=vs.71%29.aspx


line 7 is wrong. Use strcmp() with the filename (extracted with _splitpath())

http://cplusplus.com/reference/cstring/strcmp/?kw=strcmp

Like so:

1
2
if(0 == strcmp(fname, "a")) // Well typo if(0 == strcmp(fname == "a")) // Note the ""
...
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <cwchar>
#include <string>
#include <Windows.h>
using namespace std;
#include <stdlib.h>;

char response;
string fname;


int main()
{
    

    cout << "Would you like to play a game? Y/N?";

    cin >> response;
    if (response == 'y');
        cout << "What game would you like to play? Please type in exactly what the game is called including spaces, dashes, or capitalization.";
    cin >> fname;

    WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile("C:\\*",&file);
    if (search_handle)
    {
        do
        {
            if(0 == strcmp) //I dont know where to put the fname or splitpath bit 
		{CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) ||
		ShellExecute(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0)||  //handle is undefined
		//and the <fully.... expected an expression
ShellExecute(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);


    std::cout << "Found the game you wanted to play!" << std::endl;
}
        while(FindNextFile(search_handle,&file));
        FindClose(search_handle);



    system("pause");



	
    if (response == 'n')
        cout << "Goodbye!";

    //countdown
 Sleep (1 * 1000);
	 cout << "5"<<endl;
	  Sleep (1 * 1000);
	  cout << "4"<<endl;
	   Sleep (1 * 1000);
	   cout << "3"<<endl;
	    Sleep (1 * 1000);
		cout << "2"<<endl;
		 Sleep (1 * 1000);
		 cout << "1"<<endl;
		 Sleep (1 * 1000);
  cout << "CIAO!\n"<<endl;
  Sleep (1 * 1000);
  return 0;
		}  //for some reason it says that it expected 'while' 
Stop forking.
http://cplusplus.com/forum/general/98376/
http://cplusplus.com/forum/general/97861/

1
2
//if(0 == strcmp(fname == "a")) //¿?
if(0 == strcmp(fname, "a"))


@OP: Learn to indent your code, the mistake is obvious.
Also, `<fully_qualified_path_to_folder>' ¿are you serious?
Where the heck did the a come from? And anyway, you can't convert a string to a character. What the heck are you talking about?
the a came from your first post line 7.

And anyway, you can't convert a string to a character.
what is this refering to?

Follow the link how to use splitpath. Here's an exampl for it:

http://msdn.microsoft.com/en-us/library/sh8yw82b%28v=vs.71%29.aspx

1
2
3
4
5
6
7
8
9
#include <stdlib.h>
#include <stdio.h>

int main( void )
{
   char fname_from_fully_quallified_path[_MAX_FNAME];

   _splitpath(file.cFileName, NULL, NULL, fname_from_fully_quallified_path, NULL);
}



As I mentioned above <fully_qualified_path_to_folder> <= file.cFileName. You don't get that?

read this for how to use ShellExecute:

for http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx

handle -> HWND
leave that NULL!

CoInitializeEx? why? This is plainly wrong in a loop
and why this secon ShellExecute?
Topic archived. No new replies allowed.