prev up next   top/contents search

comp.lang.c FAQ list · Question 6.5

Q: Why can't I do something like this?

	extern char *getpass();
	char str[10];
	str = getpass("Enter password: ");


A: Arrays are ``second-class citizens'' in C; one upshot of this prejudice is that you cannot assign to them (see also question 6.7). When you need to copy the contents of one array to another, you must do so explicitly. In the case of char arrays, the strcpy routine is usually appropriate:

	strcpy(str, getpass("Enter password: "));

(When you want to pass arrays around without copying them, you can use pointers and simple assignment. See also question 4.1.)

See also question 8.2.

References: ISO Sec. 6.2.2.1
H&S Sec. 7.9.1 pp. 221-2


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North