Angelacolin 2014-06-01 23:09 采纳率: 0%
浏览 2864

C语言中这个指针定义是什么意思?

const char *const ch
为什么要2个const?分别是什么意思?顺便求详细说一下这个指针具体是什么意思?

编辑下,完整程序如下:

#include
#include
#include
#include

int find_char(const int, const char *const, const int);

int main(int argc, char argv) {
bool translate = false, squeeze = false, delete = false;
char *chars1, *chars2;
if (
++argv == '-') {
if (*++*argv == 's')
squeeze = true;
else if (**argv == 'd')
delete = true;
else {
printf("Unknown option -%s\n", *argv);
return EXIT_FAILURE;
}
++argv;
}
if (delete) {
if (argc != 3) {
printf("-d should be followed by exactly one string.\n");
return EXIT_FAILURE;
}
}
else if (squeeze) {
if (argc == 4)
translate = true;
else if (argc != 3) {
printf("-s should be followed by one string or two.\n");
return EXIT_FAILURE;
}
}
else if (argc != 3) {
printf("Without any option,"
" exactly two strings should be given as arguments.\n");
return EXIT_FAILURE;
}
else
translate = true;
chars1 = *argv;
if (translate && strlen(chars1) != strlen(chars2 = *++argv)) {
printf("The strings provided as arguments should have equal lengths.\n");
return EXIT_FAILURE;
}
int current, previous = '\0';
int nb_of_chars = strlen(chars1);
while ((current = getchar()) != EOF) {
if (delete) {
if (find_char(current, chars1, nb_of_chars) == nb_of_chars)
putchar(current);
continue;
}
int i = find_char(current, chars1, nb_of_chars);
if (translate) {
if (i != nb_of_chars)
current = chars2[i];
if (squeeze && (i = find_char(current, chars2, nb_of_chars)) != nb_of_chars)
current = chars2[i];
}
if (squeeze && i != nb_of_chars && current == previous)
continue;
putchar(current);
previous = current;
}
return EXIT_SUCCESS;
}

int find_char(int current, const char *const chars, const int nb_of_chars) {
for (int i = 0; i < nb_of_chars; ++i) {
if (current == chars[i])
return i;
}
return nb_of_chars;
}

  • 写回答

3条回答

  • 普通网友 2014-06-02 01:25
    关注

    楼主经常逃避结贴的话那就没人来回答了哟

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。