0

So I want store an array named buffer into an array into an array called first_line That is what I tried:

first_line = buffer;

It's obvisly that this does not work. I know that an array has many parts but how do I store it all together in one variable?

I'm a totally beginner in C and dont know what I am doing could someone help me?

7
  • 3
    Show how the arrays are declared and what they store, Commented Oct 18, 2022 at 15:52
  • I got the code from codeforwin.org/2018/01/… line 43 you will see it Commented Oct 18, 2022 at 15:55
  • 1
    You haven't shown enough code for us to accurately help, but I'll say this much. Let's assume your buffer array stores chars. Then it would be of type char []. If you want to store an array of char [], then that array would be of type char *[]. Provide some code and we can help ensure you allocate memory for these types correctly. Commented Oct 18, 2022 at 15:56
  • See this thread: stackoverflow.com/questions/57645491/… Commented Oct 18, 2022 at 15:57
  • Does this answer your question? How to copy a char array in C? Commented Oct 18, 2022 at 15:59

1 Answer 1

1

Arrays do not have the assignment operator.

If you have character arrays that store strings then you can use for example functions strcpy , strncpy or memcpy declared in header <string.h> to copy a string from one array into another.

For example

#include <string.h>

//...

char s1[] = "Hello";
char s2[sizeof( s1 )];

strcpy( s2, s1 );

To copy arrays that do not store strings you can use either function memcpy or some kind of a loop to copy element by element from one array in another.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.