Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
07-13-2008, 09:07 AM
#1
Member
Registered: Mar 2008
Location: Here - Where else?
Distribution: Fedora 12, Arch Linux (updated daily =D)
Posts: 270
Rep:
Uncompilable C++ code; can't seem to debug the program
I really have no idea what is wrong with my program to control amarok.
G++ gives me a cryptic message...
I need 2 things:
1. To know what I did wrong
2. To be able to debug things better
These may be both stupid questions; I'm an inexperienced C++ programmer.
Here's the code:
***********************************************
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
for(;;)
{
string amacommand;
cout << "Amatrol v0.1/n/nEnter command:";
cin >> amacommand;
if (amacommand = "play")
{
system("dcop amarok player play");
system("festival --tts $HOME/amatrol/play");
}
if (amacommand = "stop")
{
system("dcop amarok player stop");
system("festival --tts $HOME/amatrol/stop");
}
if (amacommand = "vup")
{
system("dcop amarok player volumeUp");
system("festival --tts $HOME/amatrol/vup");
}
if (amacommand = "vdown")
{
system("dcop amarok player volumeDown");
system("festival --tts $HOME/amatrol/vdown");
}
if (amacommand = "shuffle")
{
system("dcop amarok playlist shufflePlaylist");
system("festival --tts $HOME/amatrol/shuffle");
}
if (amacommand = "pause")
{
system("dcop amarok player playPause");
system("festival --tts $HOME/amatrol/pause");
}
if (amacommand = "exit")
{
break;
}
}
return 0;
}
************************************
What did I do wrong? any information would be useful.
( I think I indented correctly, the indents don't like to show up on LQ...
07-13-2008, 09:18 AM
#2
Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339
Rep:
Quote:
Originally Posted by
chickenlinux
I really have no idea what is wrong with my program to control amarok.
G++ gives me a cryptic message...
I need 2 things:
1. To know what I did wrong
2. To be able to debug things better
These may be both stupid questions; I'm an inexperienced C++ programmer.
Here's the code:
***********************************************
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
for(;;)
{
string amacommand;
cout << "Amatrol v0.1/n/nEnter command:";
cin >> amacommand;
if (amacommand = "play")
{
system("dcop amarok player play");
system("festival --tts $HOME/amatrol/play");
}
if (amacommand = "stop")
{
system("dcop amarok player stop");
system("festival --tts $HOME/amatrol/stop");
}
if (amacommand = "vup")
{
system("dcop amarok player volumeUp");
system("festival --tts $HOME/amatrol/vup");
}
if (amacommand = "vdown")
{
system("dcop amarok player volumeDown");
system("festival --tts $HOME/amatrol/vdown");
}
if (amacommand = "shuffle")
{
system("dcop amarok playlist shufflePlaylist");
system("festival --tts $HOME/amatrol/shuffle");
}
if (amacommand = "pause")
{
system("dcop amarok player playPause");
system("festival --tts $HOME/amatrol/pause");
}
if (amacommand = "exit")
{
break;
}
}
return 0;
}
************************************
What did I do wrong? any information would be useful.
( I think I indented correctly, the indents don't like to show up on LQ...
Well, the problem is with the
single equal = sign. You are, for example,
assigning amacommand = "play" , instead of
checking if the string matches
This is the correct way:
amacommand == "play"
Regards!
Last edited by Mega Man X; 07-13-2008 at 05:12 PM .
07-13-2008, 09:34 AM
#3
Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339
Rep:
You are using wrong escape sequences as well. At the line:
Code:
cout << "Amatrol v0.1/n/nEnter command:";
You will want:
Code:
cout << "Amatrol v0.1\n\n Enter command:";
But that should still compile. To post code in the forums with indentation, use the <code></code> tags (substitute "<>" for "[]")
Last edited by Mega Man X; 07-13-2008 at 01:21 PM .
07-14-2008, 04:13 PM
#4
Member
Registered: Mar 2008
Location: Here - Where else?
Distribution: Fedora 12, Arch Linux (updated daily =D)
Posts: 270
Original Poster
Rep:
Thank you so much! This compiles perfectly! I had a suspicion that I should use == as a comparative operator, but I thought you didn't have to do that in C++!
Thanks for the info on <code> these tags! </code>
07-14-2008, 05:32 PM
#5
Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339
Rep:
Quote:
Originally Posted by
chickenlinux
Thank you so much! This compiles perfectly! I had a suspicion that I should use == as a comparative operator, but I thought you didn't have to do that in C++!
Thanks for the info on <code> these tags! </code>
I am glad it compiled my friend. Don't feel bad about the comparative operator, we all do the same mistake once in a while between one "if" or another
Cheers!
Last edited by Mega Man X; 08-08-2008 at 05:45 AM .
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 05:39 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News