获取数组的实际长度和数组的总长度
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>#define MAX_PATH 256
char filename[MAX_PATH + 5];
int main(int argc, char** argv)
{const char* optarg = "xuhaitao";strcpy(filename, optarg);//sizeof获取数组的本身长度printf("filename2 size : %d \n", sizeof(filename));//通过strlen计算数组的实际长度printf("filename3 size : %d \n", strlen(filename));//手动计算数组的实际长度int i = 0;while (filename[i] != '\0') {i++;}printf("手动计算字符串的长度: %d", i);getchar();return 0;
}
FR:徐海涛(hunkxu)