首页上一页 1 下一页尾页 1 条记录 1/1页
C程序开发宝典第2章实例75问题
发表在C语言图书答疑
2011-03-26
是否精华
是
否
版块置顶:
是
否
原程序运行报错,为何?我用VC++编译的
#include <stdio.h>
connect(char *s, char *t, char *q);
int main(void)
{
char *str, *t, p[100];//原代码是*p,为何运行报错(提示内存不能写),我改成p[100]后OK
str = "One world";
t = " one dream";
printf("The first string is: %s\n", str);
printf("The second string is: %s\n", t);
connect(str, t, p);
printf("The connected string is:\n");
printf("%s", p);
getchar();
}
connect(char *s, char *t, char *q)
{
for (; *s != '\0';)
{
*q = *s;
s++;
q++;
}
for (; *t != '\0';)
{
*q = *t;
t++;
q++;
}
*q = '\0';
}
#include <stdio.h>
connect(char *s, char *t, char *q);
int main(void)
{
char *str, *t, p[100];//原代码是*p,为何运行报错(提示内存不能写),我改成p[100]后OK
str = "One world";
t = " one dream";
printf("The first string is: %s\n", str);
printf("The second string is: %s\n", t);
connect(str, t, p);
printf("The connected string is:\n");
printf("%s", p);
getchar();
}
connect(char *s, char *t, char *q)
{
for (; *s != '\0';)
{
*q = *s;
s++;
q++;
}
for (; *t != '\0';)
{
*q = *t;
t++;
q++;
}
*q = '\0';
}