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?

Tim
  • 1
  • 1
  • 3
    Show how the arrays are declared and what they store, – Vlad from Moscow Oct 18 '22 at 15:52
  • I got the code from https://codeforwin.org/2018/01/c-program-read-and-display-file-contents.html line 43 you will see it – Tim Oct 18 '22 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 `char`s. 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. – h0r53 Oct 18 '22 at 15:56
  • See this thread: https://stackoverflow.com/questions/57645491/how-to-store-an-array-into-an-array-in-c – JmsChf Oct 18 '22 at 15:57
  • Does this answer your question? [How to copy a char array in C?](https://stackoverflow.com/questions/16645583/how-to-copy-a-char-array-in-c) – Davis Herring Oct 18 '22 at 15:59
  • As a total beginner you should probably read a bit more before you start asking specific questions. – Peter - Reinstate Monica Oct 18 '22 at 16:13
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 19 '22 at 01:56

1 Answers1

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335