No, in the code above, if
charline = "; is not attached, the garbage value comes out, but
In the code below, why doesn't the garbage value come out even if you don't put
What's the difference between the two? You have to stick to the frozen one and you don't have to stick to the frozen one. It's so hard.c
The above code is that the for loop will spin from 9. If a short string is entered, there is a garbage value at the back of the array, and 9 is the end of the array, so the loop turns and outputs it, including the garbage value.
On the other hand, the code below obtains the length of the string entered through the strlen function and stores it in the str, and the for loop starts from the str, not from the end of the array. str is the length of the string entered, which is the index where the null character of the string is located in the array. Since the index where the null character is located is printed to the beginning of the array, the garbage value is not printed.
© 2022 pinfo. All rights reserved.