簡単な質問。私は文字列の名前を受け取ってその2番目の文字を出力する関数を書こうとしていますが、それはコンパイルされません(http://ideone.com)、問題に対処できますか?私は関数にアドレスを送り、そのアドレスの文字にアクセスするように要求しているので、問題は見えません。私は取得していますC関数内の文字列へのポインタを使用して
#include <stdio.h>
int main(void) {
char line[4] = "abc";
test(line);
return 0;
}
void test(int point) {
point++;
printf("%c",*point);
return;
}
コンパイルエラーがある - ここ
Compilation error time: 0 memory: 10320 signal:0
prog.c: In function ‘main’:
prog.c:5:2: warning: implicit declaration of function ‘test’ [-Wimplicit-function-declaration]
test(line);
^~~~
prog.c: At top level:
prog.c:9:6: warning: conflicting types for ‘test’
void test(int point) {
^~~~
prog.c:5:2: note: previous implicit declaration of ‘test’ was here
test(line);
^~~~
prog.c: In function ‘test’:
prog.c:11:14: error: invalid type argument of unary ‘*’ (have ‘int’)
printf("%c",*point);
^~~~~~
なぜ、 'char *'の代わりに 'int'を使うのですか?また、 'int'は参照を解除することもできません。 – BLUEPIXY
'test(char * point) 'にする必要があります。 – smttsp
エラーメッセージの単語を実際に読むと、それらは非常に特殊です。あなたは**実際にそれらを読む必要があります**。彼らはスクリーン上にスペースを取るだけではありません。彼らは実際に情報を伝える。 –