Random syntax errors?

so i am writing a program in c++ for a school project, but the code i am using for one of my functions is full of random syntax errors, and me and my group members can't figure out why.
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
char rCubeProcedural[4][4] (char inPT[4][4], string inKey)
{
	char **inPTClone = inPT; //defines a placeholder array

	int keyLength = inKey.length(); //gets the length of the key
	int keyPos = 0; //holds the place in the key where the program is.

	for(int i=0; i < 4; i++) //cycles through the y value of the array
	{
		for(int j=0; j > 4; j++) //cycles through the x value of the array
		{
			int ascii = static_cast<int>(inKey.get(keyPos)); //converts the ascii charecter in the key to an interger
			if(ascii > 16) //converts the integer into a usable one, less than 16, because our array is 4x4
			{
				ascii -= (ascii - 16);
			}
			int arrayY = ascii / 4; //pulls a y adress from the integer
			int arrayX = ascii - arrayY; //pulls an x value form the integer
			inPT[j][i] = inPTClone[arrayX][arrayY]; //replaces a cell of the array with one from a different location
			
			if(keyPos < inKey.length()) //cycles to the next charecter in the key
			{
				keyPos++;
			}else //unless you are at the end of the key, start over.
			{
				keyPos = 0;
			}
		}
	}

}


the problem is that the fisrt char in the declaration is underlined red, as well as both the fors, and every time i use the variable inKey. does anybody know why this might be happening?
Did you include the <string> class and use the namespace std? You have to do so to use string object.
If you didn't, that's maybe why every time you use the variable inKey it is underlined in red.

Try to add this at the beginning of your code :

1
2
3
#include <string>

using namespace std;


For the other errors, maybe someone else could help you better than me (I don't want to say something wrong)...
Last edited on
char rCubeProcedural[4][4] (char inPT[4][4], string inKey)

Are you trying to declare an array here or define a function?
Line 10:
 
for(int j=0; j > 4; j++) //cycles through the x value of the array 


The for block will never execute.
right sorry for not replying sooner, thanks for the heads up on the for loop, and the function thing, and i made sure i included all of the needed. I still get errors on my inKey.get, and on char inPTClone[4][4] = inPT, anny suggestions as to why?
If you have compile errors - then post them here in full & make sure we can see which line number in your code the errors are referring to. You can put a firstline=x (where x is the first line number) inside the opening code tag so the line number match up.

and on char inPTClone[4][4] = inPT, anny suggestions as to why?


As cire said. - maybe you meant to do assignment inPTClone[4][4] = inPT; where the declaration char inPTClone[4][4]; already exists.

Hope all goes well.
right i fixed inTPClone. as it turns out, you need to use for loops to make all the cells of two arrays equal to each other (at least in visual studios). thanks for all the help
Topic archived. No new replies allowed.