79656041

Date: 2025-06-06 14:09:22
Score: 0.5
Natty:
Report link

You're right to be confused — in C, a string like "0000000" is not empty, even though it looks like zeros.

🔹 Explanation:

If arr contains "0000000" (seven characters + a null terminator), then:

if (arr[0])

will return true, because arr[0] is '0' (ASCII 48), which is a non-zero value.

Only if arr[0] == '\0' (null terminator), the string is considered empty.

✅ To check if the string has any content:

if (arr[0] != '\0') {     // string is not empty }

But if you want to check for a string of only '0' characters, you need to loop or use:

if (strcmp(arr, "0000000") == 0) {     // arr contains exactly "0000000" }

Let me know if you're checking for zero characters or numeric zero.

checkout :https://rkoots.github.io/styleguide/

Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: rkoots