C语言字符指针Runtime错误
程序代码:
//VC6.0下,测试 #include<stdio.h> int strr_index(char *string, char letter){ char *original = string; char *ptr = NULL; while(*string){ if(*string == letter){//跟踪调试到第2次调用时在这里出错 ptr = string; } string++; } return ((*ptr)==letter ? ptr-original: string-original); } void main(void){ printf("Location of C is %d\n", strr_index("1001 C/C++", 'C')); printf("Location of x is %d\n", strr_index("1001 C/C++", 'x'));//不能执行这一步 getchar(); }