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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元