CSC209H5 Chapter Notes - Chapter 4: A.Out, Substring, Gnu Compiler Collection
Document Summary
Csc209h5s - software programming and tools (winter 2018) To store a string value, we would declare a char array where each element/character of the string is stored in one index. #include int main () { char text[ 20 ]; text[ 0 ] = "h" ; text[ 1 ] = "e" ; text[ 2 ] = "l" ; text[ 3 ] = "l" ; text[ 4 ] = "o" ; text[ 5 ] = "\0" ; printf( %s , text); return 0 ; A c string will have a null character ("\0") at the end to indicate the end of the string. By using the method above, you may be prone to errors. Here are some alternative ways to do it: #include int main() { char text[ 20 ] = { "h" , "e" , "l" , "l" , "o" , "\0" }; printf( %sn , text); return 0 ;