int main(int argc, char **argv) {
char username[256];
username = ?;
}
thanks~
You probably want to make username be a pointer, then you can just assign it:
int
main(int argc, const char *const *argv)
{
const char *username;
if (argc >= 2)
username = argv[1];
else
{
fprintf(stderr, "usage: %s username ...\n", argv[0]);
return 2;
}
/* ... */
}
But if you really want to copy the contents of the array, you are looking for strncpy.
If you want to copy another string (like argv[1]), then you probably want to use strncpy ( http://strncpy.org/ ). If you want to input it from stdin, then http://en.wikipedia.org/wiki/Fgets is probably a better bet.