C 使用指针更改字符数组的字符
没有那么复杂,我的问题是我不知道如何使用指针更改字符数组的变量C 使用指针更改字符数组的字符,c,arrays,pointers,character,C,Arrays,Pointers,Character,没有那么复杂,我的问题是我不知道如何使用指针更改字符数组的变量 #include "stdio.h" int main(void) { // Disable stdout buffering setvbuf(stdout, NULL, _IONBF, 0); char a[100], ch, *counter; int c = 0, i; counter = a[0]; printf("please enter a sentance:"); while ((ch = getchar()
#include "stdio.h"
int main(void) {
// Disable stdout buffering
setvbuf(stdout, NULL, _IONBF, 0);
char a[100], ch, *counter;
int c = 0, i;
counter = a[0];
printf("please enter a sentance:");
while ((ch = getchar()) != '\n'){
printf("yo");
*counter = ch; //problem is here
counter = a[c];
c = c + 1;
}
printf("hi\n");
for(i = c-1; i >= 0; i--){
printf("%c", a[i]);
}
return 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 );
或者甚至以下
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 );
您需要以下内容
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 );
或者甚至以下
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 );
有三个问题
while ((ch = getchar()) != '\n'){
printf("yo");
*counter = ch; //problem is here
counter = a[c];
c = c + 1;
}
到
有三个问题
while ((ch = getchar()) != '\n'){
printf("yo");
*counter = ch; //problem is here
counter = a[c];
c = c + 1;
}
到
行
计数器是否=a[0]代码>编译时抛出错误?计数器=a[0]代码>-->计数器=&a[0]代码>或<代码>计数器=a代码>,计数器=a[c]代码>-->计数器++代码>行<代码>计数器=a[0]代码>编译时抛出错误?计数器=a[0]代码>-->计数器=&a[0]代码>或<代码>计数器=a代码>,计数器=a[c]代码>-->计数器++代码>