Thread: combining two ASCII artworks.Why doesn't this work?

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    15

    combining two ASCII artworks.Why doesn't this work?

    Hi everyone, I'm a first year cs student so I don't really know what i'm doing yet. Anyways, one of our assignments is to combine two ASCII pictures (balloon and sunset) together. I have an idea of how to do it:
    Code:
    	for (int i=0; i < baloon.length(); i++){
    		if  (baloon ==" ")
    			combined[i] = sunset[i];
    		else
    			combined [i] = baloon[i];
    	}
    This should replace all the empty spaces with the other (sunset) picture, right? But i'm assuming something's wrong with the "if" statement, because all I see when I run the program is the picture of the balloon. The pictures are drawn right into the program btw. I just spent the last 3 hours thinking this through (as much as i like programming, I suck at it.) and trying different loops, because I really wanted to solve it on my own, but I definitely need some assistance. Thanks so much in advance.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You are checking if the entire string named balloon is equal to a string made of a single space.

    Character literals go between single quotes and you probably don't want to compare the whole string.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    15
    Thankyou for the reply. Is there a way to check individually then, as opposed to the whole balloon string? I tried specifying it earlier, by saying
    Code:
    if  (baloon [i] ==" ")
    but all that did was give me an error message.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Single quotes for char-s:

    Code:
    if  (baloon [i] ==' ')
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    15
    oh. right. Thanks so much for the help! three hours well spent.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  2. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 06:37 AM
  3. The simpler version of two programs doesn't work......
    By w00tw00tkab00t in forum C++ Programming
    Replies: 1
    Last Post: 02-06-2006, 07:07 PM
  4. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  5. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM