Code:char* sche = "Sep 29, 19:34";I would like to ask that 2 lines of codes above are the same meaning in C.What is the meaning of the first code and the second codeCode:char sche[] = "Sep 29, 19:34";
Thanks
Code:char* sche = "Sep 29, 19:34";I would like to ask that 2 lines of codes above are the same meaning in C.What is the meaning of the first code and the second codeCode:char sche[] = "Sep 29, 19:34";
Thanks
The first is a pointer to a string literal while the second is a 14 element array of char.
In the first case the contents of the string literal cannot be altered; in the second case the contents of sche[] can be modified.
And in the first occassion you can assign pointer "sche" to something else, while in the second you cannot assign "sche" to something else
If I declare
Then I can extract each char from "sche" by iterating through "sche.However if I try to use strtok() on schelike followingCode:char* sche = "Sep 29, 19:34";
The compiler complainsCode:char delim[] = "-"; char* token1; token1 = strtok(input,delim); printf("token1%s\n",token1);
I need some help to understand this problem. Can someone give me an answer for this.Code:red 322 % new.out Segmentation fault red 323 %
Thanks
Does that explain it better?Code:char *s = "thisisastringliteralandyoucannotmodifywhatishereinquotes"; char a[] = "thisisanarrayofunspecifieddimensionsandyoucanmodifyitscontentsprovidedyoudonotoverrunthelengthallocatedbythisassignment";
Quzah.
Hope is the first step on the road to disappointment.
the first one used as a initial expression of string,not just a pointer,which means it can't be use if not give it the space with malloc or somewhat else when you using it not as a initial expression.
the 2th shows sche is a array,it can be as large as you give to it after the = operator