大家看下这短代码的错误,搞不懂,是少什么东西吗?
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>voidprint1(cha...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
void print1(char *string)
{
printf("the string is %s\n",string);
}
void print2(char *string)
{
char *string2;
int size ,i;
size=strlen(string);
string2=(char *)malloc(size+1);
for(i=0;i<size;i++)
string2[size-i]=string[i];
string2[size+1]='\0';
printf("the string printed backward is %s\n",string2);
}
void main()
{
char test[]="hello world";
print1(tset);
print2(test);
}
错误:
test.c: In function ‘main’:
test.c:24: error: ‘tset’ undeclared (first use in this function)
test.c:24: error: (Each undeclared identifier is reported only once
test.c:24: error: for each function it appears in.) 展开
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
void print1(char *string)
{
printf("the string is %s\n",string);
}
void print2(char *string)
{
char *string2;
int size ,i;
size=strlen(string);
string2=(char *)malloc(size+1);
for(i=0;i<size;i++)
string2[size-i]=string[i];
string2[size+1]='\0';
printf("the string printed backward is %s\n",string2);
}
void main()
{
char test[]="hello world";
print1(tset);
print2(test);
}
错误:
test.c: In function ‘main’:
test.c:24: error: ‘tset’ undeclared (first use in this function)
test.c:24: error: (Each undeclared identifier is reported only once
test.c:24: error: for each function it appears in.) 展开
展开全部
第一处错误:
void main()
{
char test[]="hello world";
print1(tset);//参数名写错,应改为test
}
第二处错误:
void print2(char *string)
{
char *string2;
int size ,i;
size=strlen(string);
string2=(char *)malloc(size + 1);
for(i=0;i<size;i++)
string2[size-i]=string[i]; //应该改为string2[size-i-1]=string[i]
string2[size+1]='\0'; //应改为string2[size]='\0' 要不就数组越界,因为数组是下标是从0开始的
printf("the string printed backward is %s\n",string2);
}
void main()
{
char test[]="hello world";
print1(tset);//参数名写错,应改为test
}
第二处错误:
void print2(char *string)
{
char *string2;
int size ,i;
size=strlen(string);
string2=(char *)malloc(size + 1);
for(i=0;i<size;i++)
string2[size-i]=string[i]; //应该改为string2[size-i-1]=string[i]
string2[size+1]='\0'; //应改为string2[size]='\0' 要不就数组越界,因为数组是下标是从0开始的
printf("the string printed backward is %s\n",string2);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询