LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 07-13-2008, 10:07 AM   #1
chickenlinux
Member
 
Registered: Mar 2008
Location: Here - Where else?
Distribution: Fedora 12, Arch Linux (updated daily =D)
Posts: 270

Rep: Reputation: 31
Unhappy 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...
 
Old 07-13-2008, 10:18 AM   #2
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Quote:
Originally Posted by chickenlinux View Post
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 06:12 PM.
 
Old 07-13-2008, 10:34 AM   #3
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
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\nEnter 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 02:21 PM.
 
Old 07-14-2008, 05:13 PM   #4
chickenlinux
Member
 
Registered: Mar 2008
Location: Here - Where else?
Distribution: Fedora 12, Arch Linux (updated daily =D)
Posts: 270

Original Poster
Rep: Reputation: 31
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>
 
Old 07-14-2008, 06:32 PM   #5
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Quote:
Originally Posted by chickenlinux View Post
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 06:45 AM.
 
  


Reply

Tags
amarok, c++, control, debugging, festival, program


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Debug your Web code with Firebug LXer Syndicated Linux News 0 03-08-2007 01:01 PM
about `make` and debug source code naihe2010 Programming 9 12-13-2005 06:03 AM
How do i debug my c++ program please? twirl Programming 1 09-12-2005 03:34 AM
How to debug Linux FAT filesystem code? ashishkumbhare Programming 2 04-14-2004 03:16 PM
debug problem w/ c++ code nub47 Programming 2 12-17-2003 01:31 AM


All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration