Computer Science Canada The output of my program isn't what I want it to |
Author: | Cancer Sol [ Sat Mar 16, 2013 7:37 pm ] | ||
Post subject: | The output of my program isn't what I want it to | ||
It's supposed to output a big "Yang" that looks kinda on fire, but after being compiled and when I run it, it's really messed up. Is it because of my compiler? I'm using GNU GCC compiler btw. |
Author: | Tony [ Sat Mar 16, 2013 7:42 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
That doesn't even compile. Quote: tony$ g++ /tmp/wut.cpp /tmp/wut.cpp: In function ?int main()?: /tmp/wut.cpp:9: error: unknown escape sequence: '\040' /tmp/wut.cpp:9: error: unknown escape sequence '\)' /tmp/wut.cpp:10: error: unknown escape sequence: '\040' /tmp/wut.cpp:10: error: unknown escape sequence: '\040' /tmp/wut.cpp:11: error: unknown escape sequence: '\040' /tmp/wut.cpp:11: error: unknown escape sequence: '\040' /tmp/wut.cpp:12: error: unknown escape sequence: '\040' /tmp/wut.cpp:12: error: unknown escape sequence '\)' /tmp/wut.cpp:13: error: unknown escape sequence '\_' /tmp/wut.cpp:13: error: unknown escape sequence '\_' |
Author: | TZak [ Sat Mar 16, 2013 7:56 pm ] |
Post subject: | Re: The output of my program isn't what I want it to |
I've never coded in c++ and even I know this. Here take a look at this: Quote: #include <iostream> using namespace std; int main () { cout << " ) " << endl << " ( /( " << endl << " )\\()) ) ( ( " << endl << " ((_)\\ ( /( ( )\\))( " << endl << "__ ((_) )(_)) )\\ ) ((_))\\ " << endl << "\\ \\ / /((_)_ _(_/( (()(_) " << endl << " \\ V / / _` || ' \\))/ _` | " << endl << " |_| \\__,_||_||_| \\__, | " << endl << " |___/ " << endl; } The problem with your code is that the strings contain the escape character ("\"). I won't explain what it does, but to use it in a string you must type in two of them ("\\") and thus your output will only display as one. |
Author: | Cancer Sol [ Sat Mar 16, 2013 7:58 pm ] |
Post subject: | Re: The output of my program isn't what I want it to |
TZak @ 3/16/2013, 7:56 pm wrote: I've never coded in c++ and even I know this. Here take a look at this:
Quote: #include <iostream> using namespace std; int main () { cout << " ) " << endl << " ( /( " << endl << " )\\()) ) ( ( " << endl << " ((_)\\ ( /( ( )\\))( " << endl << "__ ((_) )(_)) )\\ ) ((_))\\ " << endl << "\\ \\ / /((_)_ _(_/( (()(_) " << endl << " \\ V / / _` || ' \\))/ _` | " << endl << " |_| \\__,_||_||_| \\__, | " << endl << " |___/ " << endl; } The problem with your code is that the strings contain the escape character ("\"). I won't explain what it does, but to use it in a string you must type in two of them ("\\") and thus your output will only display as one. Oh crap... I feel so newbie :3 I am a noob anyways though xD Thanks a lot! @Tony Well idk why, but it worked for me though :/ Goddamnit... it makes the code look so messyy now, and on the console, it looks bad Time to change how it looks |
Author: | Tony [ Sat Mar 16, 2013 8:09 pm ] |
Post subject: | Re: The output of my program isn't what I want it to |
the escape character exists so that one can describe special characters \n -- new line \t -- tab etc. Of course that leaves us with a single problem -- how to describe a sequence of characters "\n" as backslash.n instead of newline? Well, you escape the escape character! \\n Cancer Sol @ Sat Mar 16, 2013 7:58 pm wrote: @Tony Well idk why, but it worked for me though :/
Show that |
Author: | Cancer Sol [ Sun Mar 17, 2013 8:14 pm ] |
Post subject: | Re: The output of my program isn't what I want it to |
Tony @ 3/16/2013, 8:09 pm wrote: the escape character exists so that one can describe special characters
\n -- new line \t -- tab etc. Of course that leaves us with a single problem -- how to describe a sequence of characters "\n" as backslash.n instead of newline? Well, you escape the escape character! \\n Cancer Sol @ Sat Mar 16, 2013 7:58 pm wrote: @Tony Well idk why, but it worked for me though :/
Show that I don't like using \n, it makes my code look kinda confusing to me :/ I always thought \t was useless because I could just press tab myself, but I just remembered, pressing tab doesn't do anything to the output xD Here's the screenshot: http://i50.tinypic.com/2i8xa9g.jpg |
Author: | Tony [ Sun Mar 17, 2013 8:18 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
looks like escape sequences are simply discarded instead of getting caught by strict errors. |
Author: | Cancer Sol [ Sun Mar 17, 2013 8:35 pm ] |
Post subject: | Re: The output of my program isn't what I want it to |
Was I only able to compile it because my compiler discarded them? Just wondering though, did you compile it with GNU GCC compiler or was it a different one? |
Author: | wtd [ Sun Mar 17, 2013 8:53 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
It compiled because it's a valid program; just not the one you meant to write. The issue is compiler-independent. |
Author: | Tony [ Sun Mar 17, 2013 8:53 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
Quote: tony$ g++ --version i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) |
Author: | Cancer Sol [ Mon Mar 18, 2013 12:07 pm ] |
Post subject: | Re: The output of my program isn't what I want it to |
No wonder, I thought I might've posted the wrong code actually before I tested the program again Does it differ if I'm using Windows or an ios based operating system? and I've always wondered this, what's a linux? I've never really seen it before :/ |
Author: | DemonWasp [ Mon Mar 18, 2013 12:37 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
Compiler specifics vary wildly between the various platforms (operating system and CPU-type combinations, such as Windows on x86, Windows on x64, Linux x86, Linux ARM, Linux Sparc, Linux PowerPC, Linux x64, Linux Itanium, ...). Linux is an operating system kernel. It's bundled with a lot of utilities made by the GNU group, so properly the base operating system is called GNU/Linux, though most people just call it Linux. There are hundreds or thousands of "distributions" of Linux, each of which gives you a slightly different user interface and set of programs. So, when people say "linux", they usually mean "a distribution of the GNU/Linux base system, with a bunch of other stuff on top". Nearly all distributions are free and open-source. Support is generally not free, but there are communities that offer support for each distribution. You can install most distributions by downloading a CD or DVD image, burning it to disk, putting that disk in the drive and rebooting (subject to BIOS boot order and a lot of complexity I won't get into here). There are a few much-more-popular desktop distributions, including Ubuntu, Mint, and Debian (all in the same "family", with Debian being the "father"). Android is based on Linux. With Ubuntu and Mint, you can download a "LiveCD", which is just a disk that you can start the operating system from, without needing to permanently change anything about your existing computer setup. |
Author: | wtd [ Mon Mar 18, 2013 9:48 pm ] |
Post subject: | Re: RE:The output of my program isn\'t what I want it to |
DemonWasp @ Tue Mar 19, 2013 1:37 am wrote: Compiler specifics vary wildly between the various platforms (operating system and CPU-type combinations, such as Windows on x86, Windows on x64, Linux x86, Linux ARM, Linux Sparc, Linux PowerPC, Linux x64, Linux Itanium, ...).
Technically correct, but irrelevant when used to compile basic programs. |
Author: | Cancer Sol [ Wed Mar 20, 2013 6:48 pm ] |
Post subject: | Re: RE:The output of my program isn\'t what I want it to |
DemonWasp @ 3/18/2013, 12:37 pm wrote: Compiler specifics vary wildly between the various platforms (operating system and CPU-type combinations, such as Windows on x86, Windows on x64, Linux x86, Linux ARM, Linux Sparc, Linux PowerPC, Linux x64, Linux Itanium, ...).
Linux is an operating system kernel. It's bundled with a lot of utilities made by the GNU group, so properly the base operating system is called GNU/Linux, though most people just call it Linux. There are hundreds or thousands of "distributions" of Linux, each of which gives you a slightly different user interface and set of programs. So, when people say "linux", they usually mean "a distribution of the GNU/Linux base system, with a bunch of other stuff on top". Nearly all distributions are free and open-source. Support is generally not free, but there are communities that offer support for each distribution. You can install most distributions by downloading a CD or DVD image, burning it to disk, putting that disk in the drive and rebooting (subject to BIOS boot order and a lot of complexity I won't get into here). There are a few much-more-popular desktop distributions, including Ubuntu, Mint, and Debian (all in the same "family", with Debian being the "father"). Android is based on Linux. With Ubuntu and Mint, you can download a "LiveCD", which is just a disk that you can start the operating system from, without needing to permanently change anything about your existing computer setup. You can use Linux on a windows computer then? |
Author: | Insectoid [ Wed Mar 20, 2013 6:54 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
You can replace Windows with Linux on a computer. Or you can give your computer the option to use either Windows or Linux if you want to. |
Author: | Tony [ Wed Mar 20, 2013 7:26 pm ] |
Post subject: | RE:The output of my program isn\'t what I want it to |
You could run Linux in a VM though. |