是否可以在动态分配的字符串上使用strlen()
?
示例:
#include <stdio.h>
#include <string.h>
int main ()
{
char *input=NULL;
printf ("Enter a sentence: ");
scanf("%ms", &input);
//Is this legit?
printf ("The sentence entered is %u characters long.\n",(unsigned)strlen(input));
return 0;
}
答案 0 :(得分:6)
您可以在以install.packages("magrittr")
library(magrittr)
library(dplyr)
library(ggplo2)
cars_filtered <- Cars_csv %>% filter(Cylinders == 4 | Cylinders == 6)
Cars_csv %>% boxplot(cars_filtered ~ Cars_csv$Economy_highway)
结尾的strlen()
的任何序列char
上使用'\0'
,空字符又名NUL
* 1 ,实际上等于0
。
内存分配方式无关紧要。
是的,这也适用于“ 动态分配的”内存。
* 1:不能与空指针常量NULL
混用。