Timeline for Simple word translator, return error: invalid array assignment
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 18, 2015 at 10:56 | comment | added | Peter Bloomfield |
Your strncpy operations are adding the null terminators by copying them out of the string literals (string literals are implicitly null-terminated in C/C++). sizeof isn't equivalent to strlen though. sizeof gives you the size of any object, variable, or static array in bytes. strlen is only for strings, and it keeps counting characters until it reaches a null character (even if that means it goes past the end of an array).
|
|
Jan 18, 2015 at 3:35 | vote | accept | Febri Kurniawan | ||
Jan 18, 2015 at 3:34 | comment | added | Febri Kurniawan | The program above (at the question) will not make any null characters (I guess?)... and after some reading I think I got that sizeof is kind of like strlen, except it's counting any type of data? So it is interchangeable (as those string isn't null terminated?) with strlen? But now I got it clearly about memcpy. Thank you, thank you very much for your help. really thank you. | |
Jan 17, 2015 at 5:16 | comment | added | Peter Bloomfield |
No, sizeof(strlen(output)) doesn't make any sense. It would give you the size (in bytes) of the value returned by strlen() , which has nothing to do with the contents of output . Assuming the string stored in output is properly null-terminated, simply strlen(output) should tell you how many characters it actually uses.
|
|
Jan 17, 2015 at 5:05 | comment | added | Febri Kurniawan | So the sizeof(output) means we can use it like this sizeof(strlen(output)) ? Thank you! | |
Jan 16, 2015 at 10:12 | history | answered | Peter Bloomfield | CC BY-SA 3.0 |