U
uidzer0
Hey everyone,
I'm a little confused on the best way to declare character strings.
I've seen many different ways to declare them such as:
---
char string[7] = "foobar\0";
---
char *string = "foobar";
--- and ---
char *string;
string = malloc(sizeof(char) * 7);
strcpy(string, "foobar");
free(string);
----
which one of these is the best? or is there a better option?
thanks!
Ben
I'm a little confused on the best way to declare character strings.
I've seen many different ways to declare them such as:
---
char string[7] = "foobar\0";
---
char *string = "foobar";
--- and ---
char *string;
string = malloc(sizeof(char) * 7);
strcpy(string, "foobar");
free(string);
----
which one of these is the best? or is there a better option?
thanks!
Ben