Click here to Skip to main content
15,897,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone,
Im new on C and just now making my 'baby steps' here.
I will try to be clear,
I have two arrays that contains size of pairs of shoes (1 left,1 right).
First of all i goes on the two of them and finally put the quantity in a third matrix
[size][2].
I have a logical problem, I cant figure out how to put the index in the matrix.
The two arrays (left and right) are equal so i run on them together.
I hope I was clear.
Please be patient :)

What I have tried:

int left[], int s1, int right[], int s2, int sizes[SIZE][2]
	
for (int i = 0; i < left && i < right; i++) {

		if (left[i] != 0)
			s1 = left[i];
		sizes[i][1] = s1;

		if (right[i] != 0)
			s2 = left[i];
		sizes[i][2] = s2;

	}
Posted
Updated 12-Dec-21 12:50pm
v2
Comments
Richard MacCutchan 13-Dec-21 4:50am    
Why are you capturing two left feet, rather than one of each?

1 solution

First off, that is C, not C# - get your tags right, because although that look very similar they are very, very different languages and a solution for C# will not work at all in C, and a C solution would be abysmal C# code!

But you do need to remember that C arrays are zero based: and array with two elements will have indexes 0 and 1, not 1 and 2. So these lines are wrong:
C
sizes[i][1] = s1;
C
sizes[i][2] = s2;


But that seems like a very messy solution to a simple problem: have you considered using a struct instead?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900