私はCを始めたばかりなので、この質問はばかげているかもしれません. このコンパイル警告が表示され続ける理由について何か考えはありますか?
質問:文字列をにコピーするときに、改行やタブなどの文字をや などescape(s,t)
の目に見えるエスケープ シーケンスに変換する関数を作成します。\n
\t
t
s
3-2.c:37:11: warning: assignment makes integer from pointer without a cast [enabled by default]
3-2.c:38:9: warning: assignment makes integer from pointer without a cast [enabled by default]
3-2.c:42:11: warning: assignment makes integer from pointer without a cast [enabled by default]
3-2.c:43:9: warning: assignment makes integer from pointer without a cast [enabled by default]
これはコードです:
int get_line (char input[], int max_size);
void escape(char s[], char t[]);
main () {
int length, l, i;
char line[MAX], t[MAX];
while ((length = get_line (line, MAX)) > 0)
escape (line, t);
printf ("%s", t);
}
int get_line (char input[], int max_size) {
int i, c;
for (i = 0; i < max_size-1 && (c = getchar()) != EOF && c != '\n'; ++i)
input[i] = c;
if (c == '\n') {
input[i] = c;
++i;
}
input[i] = '\0';
return i;
}
void escape(char s[], char t[]) {
int i;
for (i= 0; s[i] != '\0'; ++i) {
switch(s[i]) {
case '\t' :
//This is where i get the warning.
t[i++] = "\\";
t[i] = "t";
break;
case '\n' :
t[i++] = "\\";
t[i] = "n";
default :
t[i] = s[i];
break;
}
}
}