Sunday, December 15, 2013

String / Queue / pointer problems

Brother reading a book, Programming in Objective C is
296 页Constant Character Strings and Pointers this section, see this question is very confused, solving

char * textPtr;
textPtr = "A character string.";
More feasible
char text [80];
text = "This is not valid.";
More feasible
char text [80] = "This is okay."; over and feasible

I can understand that this is a pointer to the first address textPtr C-style strings, but can not understand why (text = "This is not valid." ;) Is wrong. Is it because the default C-style string constant, can not be used to non-const assignment can only be used to initialize?

Grateful
Reply:
text = "This is not valid."; This is the first address of the array assignment to do?
char text [80] = "This is okay."; This is initialized.

c99 is so stipulated. GCC compiler should be universal
Reply:
Search to one article, I feel to say more clearly.
http://cache.baidu.com/c?m=9d78d513d9d430dc4f99e2697b13c011124381132ba6d1020ba48448e2732d455016e9ac51250773a3d13b275fa0131aacb22173441e3df2de8d9f4aaaeace7871d57275671cf1104f8c04ee96047f9a73925ceba804b4faa168c8ea85cedf5651c04e07719df08a470314c16bf41631f4a6ee1253004e&p=c3769a41999615fd08e2977c064798&user=baidu&fm=sc&query = % CA% FD% D7% E9% C3% FB +% D6% B8% D5% EB & qid = 8a87b6d50edd27ff & p1 = 5
Reply:
char text [80];
text = "This is not valid.";
Stored as an array index must be stored;
The char text [80] = "this is oK" This is actually made two moves that define an array variable and initialize an array.
If you write the first sentence should be right
char text [80];
text [0] = "This is not valid.";
This will be right.
Reply:
Reply content 404 yet?
Reply:
Looks like a bit of a problem

I also feel a little tangled up. Looks like it is feasible in the VC editor.
Reply:
I finally figured out

char text [80];
text = "1234 qwe";

In fact, this sentence is a problem. text only this time on behalf of an address constant, rather than a pointer variable

If the text to give the assignment, it should be to the right or the address of a variable with a constant address

Upstairs to that site, very useful.

I also learned
Reply:
char text [80];
The text is a constant.

No comments:

Post a Comment