Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Help in C++


  • Please log in to reply

#1
Granz00

Granz00

    Member

  • Member
  • PipPipPip
  • 226 posts
Say for example i want to open a file in Program Files then I've tried this much...

system("start C:\\Program Files");

The part that goes wrong is that it searches for 'C:\Program' but doesn't include the 'Files'. Is there a special thing to type for spaces using the '\' or something?

Also strcmp compares two strings and is case sensitive. What did you use to compare them without being case sensitive again?

Thirdly, is there a way to bundle media files with your program that way they cant be seperated?
  • 0

Advertisements


#2
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts
Hey Granz,

Say for example i want to open a file in Program Files then I've tried this much...

system("start C:\\Program Files");

The part that goes wrong is that it searches for 'C:\Program' but doesn't include the 'Files'. Is there a special thing to type for spaces using the '\' or something?

Your problem is that the start command is interpreting c:\Program Files as two parameters and only considering the first one, c:\Program. In order to get it to recognize the entire string, c:\Program Files, as the first parameter, put quotes around it, like so:
system("start \"C:\\Program Files\"");

Also strcmp compares two strings and is case sensitive. What did you use to compare them without being case sensitive again?

A common solution to case-insensitive comparison is to convert both string to either all upper or all lower case. The following code writes to the console that "Test" and "tEsT" are equal strings (compiled with Visual C++ .net 2003)

#include <iostream>

using namespace std;

int main()
{
	char string1[] = "Test";
	char string2[] = "tEsT";

	strupr(string1);
	strupr(string2);

	if(strcmp(string1, string2) == 0)
	{
		cout << "The strings are equal in a case-insensitive comparison." << endl;
	}
	else
	{
		cout << "The strings are not equal in a case-insensitive comparison." << endl;
	}

	return 0;
}

Thirdly, is there a way to bundle media files with your program that way they cant be seperated?

You can add any information you want to an exe or dll file by adding resources. If you are using Visual C++, you add a new file to your solution and select resource as the type. Then in the resource editor you add a custom type. Give it a name and up comes a binary editor. All you have to do now is get the binary data from the media file into the editor, and read it at the appropriate time during program execution. I've not ever done anything like that, so maybe someone else that is more familiar could offer some direction.

Good luck,
Ricci
  • 0

#3
Granz00

Granz00

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 226 posts
When i tried your solution for system start i typed in the code as system("start \"C:\\Program files\""); and what happened was it opened another screen when running, labeled C:\Program Files and in it it says:

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\Dev-Cpp>_

With the second problem i forgot that you use stricmp to compare strings without being case sensitive
  • 0

#4
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts

When i tried your solution for system start i typed in the code as system("start \"C:\\Program files\""); and what happened was it opened another screen when running, labeled C:\Program Files and in it it says:

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\Dev-Cpp>_


Yeah, that's all it does. It depends on what you mean by "open a file". Maybe you shouldn't be using the system function with the start command. All this does is send the parameter to the system.

The question here is, what exactly are you trying to do? What file are you trying to "open" and what are you trying to do with it once it is "open"?

-Ricci
  • 0

#5
Granz00

Granz00

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 226 posts

Yeah, that's all it does. It depends on what you mean by "open a file". Maybe you shouldn't be using the system function with the start command. All this does is send the parameter to the system.

The question here is, what exactly are you trying to do? What file are you trying to "open" and what are you trying to do with it once it is "open"?

-Ricci


I found an answer to my problem, in example for C:\Program Files\Test[1].wav i use

system("start C:\\PROGRA~1\\TEST_1~1.wav");

you have to use up to the first 6 letters followed by ~1 and you dont include spaces or periods. There are more details but you just gotta look those up yourself...

And btw, what is the way you would open, for example, a song?
  • 0

#6
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts
Hi Granz,

Ok, now that I know you're trying to open a sound file, here's one way to do it without using the short naming conventions:

system("\"c:\\Program Files\\Test[1].wav\"");
You just have to use quotes so that the system recognizes the entire path as one string. Also, note that I left off the "start" portion. It seems to only work with short names for some reason.

And btw, what is the way you would open, for example, a song?

You can use the same technique that you are using for Test[1].wav. This technique just passes the string parameter to the command line to be executed. If the only thing the command line is given is a path, it will check your file associations for the appropriate app to use the file.

It is important to note that this is extremely machine specific. For example, on my machine Windows Media Player is associated with .wav files, so that's what runs for me when my machine executes this code. Someone else's machine might use Real Player or WinAmp or something else. Also note that whatever program runs to use the file, it probably won't go away afterwards. So, even though your program terminates and goes away, there is still another program left around.

-Ricci
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP