Function issues

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 <shellapi.h>
#pragma comment(lib,"shell32.lib")
static HWND hBut;
#define ShellExecute;

char response;
string a;


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 >> a;

    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>, 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);


    }

    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;
}


My function is the issue. I'm not sure how to write a correct function to search your computer for file 'a'. If anyone knows how to correct it or get rid of anything unneccesary I would be extremely grateful.
Last edited on
Delete lines 6 through 9
Since your indentation is all over the place, it's hard to tell what your intention is - did you really intend line 33 to be the only line that is conditional upon the test in line 32? The indentation makes it look as though you also intended line 34 to be conditional. As a general guideline, always put braces around a conditional code block, even when it's only a single line, i.e.

1
2
3
4
5
6
7
8
9
  // Instead of this:
  if (a < b)
    std::cout << "a is less than b" << std::endl;

  // Do this:
  if (a < b)
  {
    std::cout << "a is less than b" << std::endl;
  }


That way, if you ever want to add more lines to your conditional code block, you don't run the risk of forgetting to add the braces.

What's the point of enclosing line 38 in its own block?
Thanks, I took all your advice into consideration. Here is my function, which seems to be the problem, as everything else works:

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);




Last edited on
Topic archived. No new replies allowed.