简体   繁体   中英

Clarification on strcpy

I am currently learning C via edube.org and came across something that didn't quite agree with my observations when I run the code in Code blocks.

For example: edube.org says that The invocation:

strcpy(string, "Alice has a cat");

fills the array string with the string Alice.

I initially thought (just going by the above statement in edube.org) that this is probably because the space after "Alice" may have been considered a null character '\0' marking the end of the character. But this does not seem to be the case. I am just looking for clarification to convince myself that edube.org is indeed incorrect.

Either you read wrong or the site is wrong.

strcpy(string, "Alice has a cat");

This fills the character array with the string "Alice has a cat" .

The null character (ASCII code 0) is a distinct character that cannot be typed from the keyboard directly. In C, it is represented by \0 and is appended by default at the end of all string literals. It should not be confused with the space character (ASCII code 32), which is just a regular character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM