【发布时间】:2014-01-20 08:59:33
【问题描述】:
我会从 ISBN 字符串中删除“-”。 但是我的代码不会打印出我的价值。错在哪里?
char *ISBN[20]; //example: 3-423-62167-2
*p = ISBN;
strcpy(ISBN, ptr); //Copy from a Buffer
printf("\nISBN Array: %s", ISBN); //This works!
while(*p)
{
if (isdigit(*p))
{
long val = strtol(p, &p, 10);
printf("%ld\n", val); //Do not show anything!
}
else
{
p++;
}
}
【问题讨论】:
-
p的声明是什么? -
char *ISBN[20]?当然?数组数组? -
只需
char ISBN[20]就足够了。那里有一个 C 字符串数组 -
@Adriano 不,这是一个指针数组。
-
另外,@OP:
strtol()不会做你认为的那样。 阅读其文档。