Follow

Deleting an unused variable makes my code seg fault....

@matrix you're already corrupting somewhere the stack and the unused variable is just accidentally saving you from the effects of that.

@apropos
In C, can I have an array of strings and then do strcpy into it like strcpy(strings[i], str)?

@matrix @apropos if you have adequate space in the destination buffer, then yes. Also don’t forget about the null terminator.

@matrix @apropos It copies it over, if that’s what you mean, but it doesn’t create one if it doesn’t exist.

@VD15 @matrix

#include #include int main(void) { char strs[2][3] = {"ab", "cd"}; strcpy(strs[0], "xx"); printf("%s\n%s\n", strs[0], strs[1]); }

Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.