首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

字符串长度,该如何处理

2013-06-26 
字符串长度#includestdio.hint main(void){const char *mytal[5]{adding numbers swiftly,multiplyi

字符串长度

#include<stdio.h>
int main(void)
{
const char *mytal[5]={"adding numbers swiftly",
"multiplying accurately",
"stashing data",
"following instructions to the letter",
"understanding the c language"};
printf("%s\n",*mytal[3]);
char mytal_2[5][]={"adding numbers swiftly",
"multiplying accurately",
"stashing data",
"following instructions to the letter",
"understanding the c language"};
printf("%c\n",mytal_2[5][10]);
return 0;
}

其实我想问的是,上面指针数组字符串长度由初始化字符串决定,那二维数组可不可以,因为我不知道字符串中要放多少字符,char mytal_2[5][]这种形式可不可以 二维数组 指针数组
[解决办法]
 printf("%s\n",*mytal[3]); 打印串,得是个地址,不能有*
printf("%c\n",mytal_2[5][10]); 5长度的数组,下标最大为4,越界了。
字符数组需要先知道长度。mytal_2[5][] 是不可以的,如果不知道长度,可以定义指针数组,然后使用malloc动态分配内存

热点排行