Issue Copying Text from one String to Another

I posted here the other day about an issue I was having a program I have written in that it wouldn't compile. Now I have run into another problem.

Before I begin asking my question though I would like to note that I am asking a question about a program that I am required to write for my college (Seneca College) but that I do not want someone to solve it for me or give me the answer or something along those lines, just to help point me in the right direction or understand exactly what is going wrong.

The problem is that I am trying to copy data from a string sent to my function over into another string, but it's adding a weird triangle on at the end and I have no idea why it's doing this. Here is what I mean. I printed off the character from the string sent and the character from the string the data is being put into afterwards, that is why there are double letters. The word I am copying over is "look".

Here is what I get:
http://img.photobucket.com/albums/v341/overmindrf/what.jpg?t=1276741240

I am compiling two files, one of which includes a file (#include "command.h") that contains the class I am accessing. The other file is provided to us and is the main, and the compiler seems to be telling me that that is where the errors are coming from.

Here is the main he provided us with:
http://pastebin.com/ypeEa9AF

Here is the program I wrote:
http://pastebin.com/nq4PdLFJ

The function that I believe is causing the problem is the very first one.

Here is the class:
http://pastebin.com/3UP2qyup

Any and all help would be greatly appreciated. I'm entirely unsure as to what is causing the problem, because it keeps telling me it's in his program (a2main.cpp. My code is command.cpp and the class is command.h). If any other information is required, please ask.

Thank you in advance.
I don't know what the policy is on bumping here but, small bump in hopes of finding out what this problem is.
I can't reproduce your problem with the code but this may be your error:

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void command::init(char data[])
{
	int a = 0, b = 0, c = 0, keycheck = 0;
	for(a = 0; data[a] != '\0'; a++)
	{
		if(data[a] == ';' && c != 5)
		{
			a++;
			//moves the data array past the ; to the actual modifier
			for(b = 0; data[a] != ';'; b++)
			{
				modifier[c][b] = data[a];
				a++;
				//continues moving us through the data array to
				//get all of the modifier
			}
			count++;
			c++;
			//Very important for my code. Not only does it control
			//The first indice (Spelling?) of the modifier char
			//array, but it also stops the first if statement from
			//running if it hits 5. This is because we are only
			//suppose to take 5 modifiers, and when c hits 5, 5
			//modifiers have been taken.

		}
		else if(keycheck != 1)
		{
			// == Galik ==
			// keyword never gets the string terminator
			// appended to the end because the loop stops
			// when it reached the '/0' char in data[].
			keyword[a] = data[a];
			keycheck = 1;
		}
	}
	// == Galik ==
	// append it here
	keyword[a] = '\0';
}
That did actually solve it, thank you! There seemed to be an issue with the nullbyte, so placing it in at the end solved the problem. The only thing I had to do before that was initialize the keyword and modifier arrays as " ".

Thank you again for your help.
Topic archived. No new replies allowed.