ASCII Artwork and RLE code

Ok I am trying to make a program that will decode and run RLE code for ASCII artwork. We are supposed to use a certain function that will first ask the user for the Encoded parts (ie. 11:+8:.2:+8:.2:+8:.11:+) this meaning it will display 11 + signs then 8 . then 2 + and so on. I am not sure what the : is there for but we need to use this line exactly as is. Then it will save each into a multidimensional array and then display the array. I have the array and coding to display it.

I am having an issue from the start of entering the information and have been stuck a while now. When I do the coding

cout << "Enter ASCII coding: ";

and paste the whole thing 11:+8:.2:+8:.2:+8:.11:+ into the command line it all saves as one string and does not separate any of the numbers or anything. We are not aloud to enter it any differently simply as I have entered it here is how it is to be entered in the command box. No spaces, entered all at once.

Any help is very much appreciated. Thanks guys
See, what you'll have to do is to look for a number (11, 8, 2, etc) (perhaps using strtok function). Then skip one string element (which will be :), and check the next symbol (+, . or whatever). Then print that symbol that number of times. Continue through the string till the end.
Note that for two digit numbers, you'll have to check for consecutive numbers, and then club them together. Some manipulation like that...
(This post may not be very clear, so I'll try posting a snippet of code later. But hope this helps for now!)
Thanks, I am still a first year and we JUST have not even taken a class on that so there may be another way but he does not prohibit us from using code we have yet to learn. I researched the strtok and seems like a good method to use. Ill try it and if anyone has some example code it would help a little. Thanks
I'll post an example snippet of code later regarding your program to help you out... :)
Just for further explination of what I need to do here I have typed out what it is we are supposed to do. Please remember I am not wanting anyone to do the work for me just to let me know how they think it best to go about doing this.

"For this part you will be writing the function that reads, and decodes, a runlength encoded piece of ASCII art. See the above section on runlength encoding for the format that the input through the console will have.
This function will have as input (through parameters): a single two-dimensional array that is 80 rows by 80 columns; an integer, R, indicating the number of rows in the ASCII art; and an integer, C, indicating the number of columns in the ASCII art.
The very first line of this function should be the code:

cin >> noskipws;

This will tell cin to not ignore whitespace when reading in a single character.
The very last line of this function should be the code:

cin >> skipws;

This will tell cin to start ignoring whitespace again.
Note: You will have to #include <iomanip> in your program for this to work.
You can test that your function works by creating an 80 row by 80 column two-dimensional array of characters in your main function, calling your new function with that array and an R of 5 and a C of 10, then calling your function from part 1a with an R of 5 and a C of 10. If you run your program, and copy & paste the text "11:+8:.2:+8:.2:+8:.11:+" (without the double-quotes) into your console then your program should print out the box that you see in the discussion of runlength encoding above."

And it should print out this (I edited so it looked right on here)

++++++++++
+ . . . . . . . . +
+ . . . . . . . . +
+ . . . . . . . . +
++++++++++
Last edited on
Hmm... It clarifies the problem further... Don't worry, I won't post the actual code here, I know better than that... So from this, there arises the small issue, of indicating to the program to go to the next row, when the first is used up... I'm not sure, but the logic would be slightly lengthy.. So what next do you need help with...?
Well as I said I have the array setup as well as the code to display it. My issue is still as it was, I need to find a way to have it ask for the code so:

cout << "Enter Code: ";

then you will paste code for example

11:+8:.2:+8:.2:+8:.11:+

in the console window. I am not really sure how to break that down in code and what way is best. Should I just save it as a string: cin >> string code;

The only way I was thinking this would work for what I can think of is if I do it this way and perhaps use a loop to find find the first number int the string, give that numbers value to int x then erase the number and : from the string and use the next char in the string. then another loop to display the number of char there is.

I am not 100% on the code I could use to do this but its about all I can think of. do you think there is a simpler way?
1
2
3
int quantity;
char separator, filler;
cin>>quantity>>separator>>filler;
¿is there a problem with that?
Nope that does work, my only issue is with that is if I have an ASCII code that requires it to be 80 x 80, how do I reuse the same 2 char and the 1 int value over and over again. From what I understand with user input you can only get the cin once for each user input so for example

cout << "Enter ASCII code: ";
int quantity;
char separator, filler;
cin << quantity << separator << filler;

and input being
11:+8:.2:+8:.2:+8:.11:+

will get quantity as 11, separator as : and filler as +

I can use a loop to do the 11 + signs but once that is done how do I get the next 3 parts out of the entered code without re entering it? I dont really want to make 240 variables for an 80 part code.
Last edited on
ok so trying to use a loop to do this I have this so far
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
	cin >> noskipws;
	int num;
	char garbage;
	char set;
	int r;
	int c;
	cout << "How many rows and columns: ";
	cin >> r >> c;
	string test[r][c];
	cout << "Enter ASCII code: ";
	for (int i=0; i<r; i++)
		{
			cin>> num >> garbage >> set;
			for (int j=0; j<c; j++)
				{
					for (int k=0;k<num; k++)
						{
							test[i][k]=set;
						}
					cout << test[i][j];
				}
			cout << endl;
		}
	cin >> skipws;
}


It asks how many rows and columns then about the ASCII Code but it does not let me input anything.. whats wrong with it.

1
2
cin>>noskipws;
cin>>r>>c; // ¿how are you separating the numbers? 
Also, your loop is incorrect.

You could take the input until the user set quantity = 0
Yeah, shift line 2 to after you've accepted number of rows and columns. Also, line 21 is unnecessary, it will interfere in the input.
Also, this program will accept only one line of the type "8:+" or whatever, one at a time... You need your program to accept an entire string, then cut it up into pieces of the type "number:symbol" and then interpret it and display output accordingly...
EDIT: Okay, so you've already mentioned this in your post.. Sorry I didn't read through... So wait up, I'll post a snippet of code a little later to set you on your way.. :)
Last edited on
Topic archived. No new replies allowed.