Home > Back-end >  Questions about C language character array.
Questions about C language character array.

Time:11-10

A one-dimensional character array can store a string? If not how to achieve?

CodePudding user response:

The end of the string is' \ 0 ', you can define a bigger space, depositing multiple strings, separated by '\ 0', for example:
Char buf [1024].
Char * strings [4]={buf, & amp; Buf [9], & amp; Buf [17], & amp; Buf [24]}.

Memcpy (strings [0], "abcdefg", 8).
Memcpy (strings [1], "hijklmn", 8).
Memcpy (strings [2], "opqrst", 7);
Memcpy (strings [3], "uvwxyz", 7);

Strings and an array of strings

CodePudding user response:

Two-dimensional array is essentially a one-dimensional array,
Prev:?
  • Related