LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 08-27-2003, 06:03 PM   #1
mandrakeroot
LQ Newbie
 
Registered: Jul 2003
Distribution: Gentoo 1.4
Posts: 6

Rep: Reputation: 0
Question STILL NEED HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Im having some trouble with a program ive been trying to make.
I need to compile this:
Code:
using namespace std;
#include <iostream>
#include <iomanip>

int main()
{
  cout <<"    *****    " << endl;
  cout <<"   *     *   " << endl;
  cout <<"  * -   - *  " << endl;
  cout <<" *  o   o  * " << endl;
  cout <<"*     |     *" << endl;
  cout <<" *    +    * " << endl;
  cout <<"  * \___/ *  " << endl;
  cout <<"   *     *   " << endl;
  cout <<"    *****    " << endl;
  cout <<"   "happy"   " << endl;
  return 0;
}
but when trying to compile i get this:
Code:
tux@localhost tux $ g++ ex12.cpp
ex12.cpp:13:10: warning: unknown escape sequence '\_'
ex12.cpp: In function `int main()':
ex12.cpp:16: syntax error before string constant
Help would be appreciated!

Last edited by mandrakeroot; 08-27-2003 at 06:24 PM.
 
Old 08-27-2003, 06:13 PM   #2
SMB3Master
Member
 
Registered: Aug 2003
Location: USA
Posts: 32

Rep: Reputation: 15
oh...

Last edited by SMB3Master; 08-27-2003 at 06:15 PM.
 
Old 08-27-2003, 06:18 PM   #3
mandrakeroot
LQ Newbie
 
Registered: Jul 2003
Distribution: Gentoo 1.4
Posts: 6

Original Poster
Rep: Reputation: 0
Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  cout <<"    *****    " << endl;
  cout <<"   *     *   " << endl;
  cout <<"  * -   - *  " << endl;
  cout <<" *  o   o  * " << endl;
  cout <<"*     |     *" << endl;
  cout <<" *    +    * " << endl;
  cout <<"  * \\___// *  " << endl;
  cout <<"   *     *   " << endl;
  cout <<"    *****    " << endl;
  cout <<"   "happy"   " << endl;
  return 0;
}
I still get compile erros:
Code:
tux@localhost tux $ g++ ex12.cpp
ex12.cpp: In function `int main()':
ex12.cpp:16: syntax error before string constant
tux@localhost tux $
I dont know what is wrong
 
Old 08-27-2003, 06:41 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
try
Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  cout <<"    *****    " << endl;
  cout <<"   *     *   " << endl;
  cout <<"  * -   - *  " << endl;
  cout <<" *  o   o  * " << endl;
  cout <<"*     |     *" << endl;
  cout <<" *    +    * " << endl;
  cout <<"  * \\___/ *  " << endl;
  cout <<"   *     *   " << endl;
  cout <<"    *****    " << endl;
  cout <<"   \"happy\"   " << endl;
  return 0;
}
 
Old 08-28-2003, 07:23 PM   #5
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
// sequence is a comment, no?
 
Old 08-29-2003, 01:26 PM   #6
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
Talking I have your answer...

I tried to include my own version of your fixed source, but everytime i previewed my post...the code's formatting was lost and yes, i did try to include it as code. So when I refer to a line number, count down your code - with the first include being line #1.

The first fix was on line #14, the smile was confusing the compiler. You see, on the first try you entered in \__/ which translates to the escape sequence \_ (which doesnt exist) followed by underscores and finally a / . This is not what you wanted. So in order to include a \ character into a string statement you need to use the escape sequence \\ which translates into a single \ .

That takes care of the smile, next we tackle the "syntax error before string constant" error. That error is on line # 17. You had this: cout << " "happy" " << endl; what you wanted was the word happy with quotes, with white space on both sides. But when the compiler sees this, it thinks happy is a variable since it is outside of the two sets of quotes! It thinks you meant this: cout <<" " << happy << " " << endl ; But you just goofed up and didnt put that other <<operator in! What you needed were two \" escape sequences before and after the happy to print two quotes and not end your string.

I hope this helps!

 
Old 08-29-2003, 01:27 PM   #7
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
oops

Seems like someone already answered the question!
Oh well.
 
Old 09-04-2003, 10:37 PM   #8
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Never cared for the smiley face algorithm's i've seen, in book's nor in actual code, for me, despite the many book's, which, in fact, had little to do with smiley face's, never gave me a sense of tightness that i was looking for in smiley face code, oh we'll. :D
 
Old 09-05-2003, 06:11 AM   #9
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
if by tightness you mean compactness then how about this
Code:
#include <iostream>
/*
  0x81006600423c0081 badly drawn smiley face
  0x383810fe10284482 man standing
*/
int main()
{
    for(int bit=63;bit>=0;bit--) {
        if((long long)1<<bit & 0x81006600423c0081) std::cout<<'#'; else std::cout<<' ';
        if(!(bit % 8)) std::cout << std::endl;
    }
    return 0;
}
ive included a man standing because he looks so much better than the crap smiley face i did(need a bigger datatype something with maybe 144 bits) the only reason i used c++ was so i could declare bit inside the for loop.

Last edited by kev82; 09-05-2003 at 06:18 AM.
 
Old 09-06-2003, 01:53 AM   #10
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
I try to compile your code, kev82, and it gives me this.

Code:
smile.cpp: In function `int main()':
smile.cpp:9: error: integer constant is too large for "long" type
 
Old 09-06-2003, 05:30 AM   #11
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
you must have quite a pedantic compiler, on line 9 put ll after the hex number, ie
Code:
if((long long)1<<bit & 0x81006600423c0081ll)
if that doesnt work i suggest you try a different gcc, there have been errors reported in gcc 3.3. ive compiled it on gcc 3.2.1 and sun's C++ compiler(wont tell me version) no problem but on gcc 2.95.2 the ll was needed.
 
Old 09-06-2003, 05:47 AM   #12
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
Yes, my compiler is gcc 3.3. I added ll and it works now.
 
Old 09-06-2003, 07:11 PM   #13
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Quote:
Originally posted by kev82
if by tightness you mean compactness then how about this
Code:
#include <iostream>
/*
  0x81006600423c0081 badly drawn smiley face
  0x383810fe10284482 man standing
*/
int main()
{
    for(int bit=63;bit>=0;bit--) {
        if((long long)1<<bit & 0x81006600423c0081) std::cout<<'#'; else std::cout<<' ';
        if(!(bit % 8)) std::cout << std::endl;
    }
    return 0;
}
ive included a man standing because he looks so much better than the crap smiley face i did(need a bigger datatype something with maybe 144 bits) the only reason i used c++ was so i could declare bit inside the for loop.
Hi kev, that's quite complex, i like....but mabey something a little more 'C' shall we...
Code:
int main(int argc, argv*)
{
        if (argv[0] == '--help')
        printf("Please enter your mood, :( , :P , ;));
        else if (argv[1] == ':(' || argv[1] == ':P' || argv[1] == ';)')
        printf("\n\n\n:)\n\n\n");
        else 
        printf("Bad Commandline Argument, please type '--help' for assistance");
        return 0;
}
I didn't compile this code, so excuse any mistake's, but hopefully you get the genreal idea. :D

Last edited by Tarts; 09-06-2003 at 07:17 PM.
 
  


Reply


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
escape sequence help in C name_in_use450 Linux - General 6 07-01-2004 10:23 AM
smiley face on windows? shanenin Linux - Software 1 05-19-2004 01:30 PM
escape sequence for changing color of prompt killer_bunny Linux - General 1 02-10-2004 08:40 PM
Smiley problem darthtux LQ Suggestions & Feedback 1 08-22-2003 06:14 PM
face to face in Malaysia ... Penang thomassounness Linux - Newbie 3 06-29-2003 07:09 PM


All times are GMT -5. The time now is 01:38 PM.

Main Menu
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