我刚开始 C 所以这个问题可能很愚蠢。关于为什么我不断收到此编译警告的任何想法?
问题:编写一个函数escape(s,t)
,将换行符和制表符之类的字符转换为可见的转义序列,例如\n
and ,\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;
}
}
}