# Thread: Array equal to array

1. ## Array equal to array

Hey everybody, I know I am doing this wrong but I forgot the right way to do this...
Code:
`answer[answerplace] = question[find];`
this is in a loop that keeps repeating until a character is found. But I am
doing
Code:
`answerplace++;`
while I am doing
Code:
`find++;`
thinking it will put the place from question into the place from answer, this doesn't work but I know this is done another way that I forgot.

2. I don't know what it is you're trying to do, but your explanation is terrible. Your first line just assigns a value from one array to another. It doesn't compare anything. If you aren't trying to compare, then just do:
Code:
```for( x = 0; x < size; x++ )
array1[ x ] = array[ x ];```
Quzah.

3. I was just wondering it I could make do something like

Code:
`answer[answerplace] = question[find];`
and while "answerplace" and "find" equal two different numbers. I keep on getting a segmentation fault for it.

Thanks.

EDIT: I am trying to make answer equal to question.

4. Did you make sure you aren't getting out of bounds on an array?

5. Originally Posted by xniinja
I was just wondering it I could make do something like

Code:
`answer[answerplace] = question[find];`
and while "answerplace" and "find" equal two different numbers. I keep on getting a segmentation fault for it.

Thanks.
Simple - just make sure you don't exceed the bounds of either array...

6. when I initiate them I do

Code:
```char question[find];
//and
but when I initiate answerplace I make it equal to 0 should I make it 20 or something.

7. oh it worked thanks guys.

8. Originally Posted by xniinja
when I initiate them I do

Code:
```char question[find];
//and
but when I initiate answerplace I make it equal to 0 should I make it 20 or something.
Um...why would you declare a zero-length array? Maybe you should post a working program to demonstrate more clearly how you are doing things.

9. The program is attached. It has some glitches. Like when you enter a question with a space in the test maker it will skip over the answer and go back to question (you'll see). This program (if you fix it) can be used to study.

Can you tell me about some glitches you find, thanks.

EDIT: i also initiate some values midcode.

10. I don't know who is teaching you C but you should inform them they are doing a terrible job.

This is always true: while( loopkey == 'y' || '\n' ) Because even if loopkey is not 'y', '\n' is a non-zero (true) value. Try while( loopkey == 'y' || loopkey == '\n' ) Similarly you do stuff like while( looper != looping ) which is fairly redundant and easy to confuse people by. Should looper change or looping change to stop the loop? Neither is a constant....

You don't really understand too much about functions either.

Code:
```type fun ( type paramA, type paramB );

type fun ( type paramA, type paramB )
{
... code ...
return [a type variable];
}```
Functions have many parts, all of which are highlighted: the return type, the function name, the different types of parameters, the parameter names, and braces. Each part is arranged in the manner that you see.

The first part is called a function prototype. These statements typically live in #included header files (.h files), and are there to inform the compiler of a particular function's existence. It is so the compiler can statically check types of arguments (the things passed into a function) against the corresponding parameter (what the function calls the argument) types. These are also handy, since you can now define the function at any time, such as after main() or in a .c file.

As for the flash card program... I'm still not very clear on what you mean to ask. Flash cards have two sides, a clue side and an answer side... I can't think of a time when you should make both sides the same thing through assignment. It's always a mistake to do that.

If you mean to compare a lot of the end user's answers to the actual flash cards you could compare with the equality symbol, in a loop:

Again though, I would think the question side of the flash card is only used to show him the question. The clue part of the flash card is not going to be helpful in deciding whether he's right or wrong.

11. That would be myself for I am on 15. And my school doesn't have any programming classes. Thank you.

12. Originally Posted by xniinja
That would be myself for I am on 15. And my school doesn't have any programming classes. Thank you.
Ok what are you using for text books?

You should do all the examples in the books... but don't just compile them and go "cool"...
make changes, do things to make them stop working. You need to know what doesn't work
just as much as you need to know what does.

13. Also noticed this

Code:
`while(questionloop = 'y')`
That is not going to compare if the questionloop hold 'y'. Insided it going to aassign questionloop with the value 'y' overriding whatever the questionloop already had. You will have careflul with these things, can get worse when working a huge projects.

ssharish

14. Originally Posted by CommonTater
Ok what are you using for text books?

You should do all the examples in the books... but don't just compile them and go "cool"...
make changes, do things to make them stop working. You need to know what doesn't work
just as much as you need to know what does.
Its just a hobby... Well it didn't start as a hobby. My dad threw me into it when he wanted a calender program (it got half done). I "worked" for him last summer. And all the code I write isn't from a book its all from scratch, I don't even have a book (probably a good investment though) I started last summer by watching Youtube videos. So yea... this isn't some stuff I just copy out off a book and ask help on it. Also thanks for the tip, I appreciate it.

15. Originally Posted by xniinja
Its just a hobby... Well it didn't start as a hobby. My dad threw me into it when he wanted a calender program (it got half done). I "worked" for him last summer. And all the code I write isn't from a book its all from scratch, I don't even have a book (probably a good investment though) I started last summer by watching Youtube videos. So yea... this isn't some stuff I just copy out off a book and ask help on it. Also thanks for the tip, I appreciate it.
No cost to you....