//my code is
#include <stdio.h>
int main() {
char txt[] = "xyz";
printf("%d", strlen(txt));
return 0;
}
//error is strlen is not declared in this scope
//it should work my code is correct
On
strlen(). More info here.#include <stdio.h>
#include <string.h> // The header you were missing
int main(void) {
char txt[] = "xyz";
printf("%zu", strlen(txt));
return 0;
}
https://en.cppreference.com/w/c/string/byte/strlen says:
P.S. It also says that the return type is
size_t, which is unsigned, and https://en.cppreference.com/w/c/io/fprintf says that the printf specifier forsize_tisz, so the format string should be"%zu".