它并不复杂,我的问题是我不明白如何使用指针更改字符数组的变量
getScore(form);
错误是"退出非零状态"
答案 0 :(得分:0)
您需要以下
counter = a;
^^^^^^^^^^^
printf("please enter a sentance:");
while ((ch = getchar()) != '\n'){
printf("yo");
*counter++ = ch; //problem is here
++c;
}
while ( c != 0 ) printf("%c", a[--c]);
甚至以下
counter = a;
^^^^^^^^^^^
printf("please enter a sentance:");
while ((ch = getchar()) != '\n'){
printf("yo");
*counter++ = ch; //problem is here
}
while ( counter != a ) printf( "%c", *--counter );
答案 1 :(得分:0)
有三个问题。
counter =&(a [0]);
或更好
counter = a;
与第1点相同。你不必这样做,因为计数器已经指向数组。只需递增指针。
更改
while ((ch = getchar()) != '\n'){
printf("yo");
*counter = ch; //problem is here
counter = a[c];
c = c + 1;
}
到
i = 0;
while ((ch = getchar()) != '\n' && ((sizeof(a)/sizeof(a[0])-1)>c)){
printf("yo");
*counter = ch;
counter++;
c++;
}
*counter = '\0';