1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
int main(int argc, char* argv[]) {
char* s = "emperor penguin (Aptenodytes forsteri)";
size_t s_length_chars = strlen(s);
printf("strlen(\"%s\") is %zd characters. This does not count the '\\0'.\n", s, s_length_chars);
// size_t is an integer type (like int) that is used to hold the size of a string or region of memory.
// strlen(…) returns the number of characters in a string, not counting the null terminator ('\0').
// You must have #include <string.h> in order to use strlen(…).
// Do not try to use sizeof(…) to measure the length of a string.
// Always check the allowed symbols table in an assignment to find out which standard function you can use.
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2021 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.