
C语言问题,提示的error全都是stdio.h出错,我哪写错了。。。。
这个是ex09.h#if!defined(__EX08_15_H_INCLUDED__)#define__EX08_15_H_INCLUDED__//----------...
这个是 ex09.h
#if !defined(__EX08_15_H_INCLUDED__)
#define __EX08_15_H_INCLUDED__
//------------------------------------------------------------------------------
// basic constants
//------------------------------------------------------------------------------
#define FALSE 0
#define TRUE 1
#define MAXSTRLEN 32767
//------------------------------------------------------------------------------
// simple types
//------------------------------------------------------------------------------
typedef int BOOL;
typedef unsigned int POS;
typedef unsigned int COUNT;
typedef int DIR;
typedef char STRING[MAXSTRLEN+1];
typedef char* PSTRING;
#endif // #if
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos);
PSTRING Insert(PSTRING str,char a,POS pos)
这个是ex09.c
#include "ex09.h"
#include <stdio.h>
//------------------------------------------------------------------------------
// main function
//------------------------------------------------------------------------------
void main()
{
PSTRING str = "abcdefg";
PSTRING sub = "abc";
PSTRING res;
res = String_Insert( str, sub, 3 );
printf( "%s\n", res ); //abcabcdefg
}
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos)
{
int i;
char a;
for(i=0;sub[i]!='0';i++)
{
a=sub[i];
str=Insert(str,a,pos+i);
}
return str;
}
Insert(PSTRING str,char a,int pos) //插入函数,将a插入str字符串的第pos个后面
{
char b,c;
c=b=str[pos];
str[pos]=a;
pos++;
for(;str[pos-1]!='0';pos++)
{
b=str[pos];
str[pos]=c;
c=b;
}
return str;
}
要求编写字符串插入函数String_Insert,将字符串sub插入到字符串str中,插入位置为pos(从0开始)。 展开
#if !defined(__EX08_15_H_INCLUDED__)
#define __EX08_15_H_INCLUDED__
//------------------------------------------------------------------------------
// basic constants
//------------------------------------------------------------------------------
#define FALSE 0
#define TRUE 1
#define MAXSTRLEN 32767
//------------------------------------------------------------------------------
// simple types
//------------------------------------------------------------------------------
typedef int BOOL;
typedef unsigned int POS;
typedef unsigned int COUNT;
typedef int DIR;
typedef char STRING[MAXSTRLEN+1];
typedef char* PSTRING;
#endif // #if
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos);
PSTRING Insert(PSTRING str,char a,POS pos)
这个是ex09.c
#include "ex09.h"
#include <stdio.h>
//------------------------------------------------------------------------------
// main function
//------------------------------------------------------------------------------
void main()
{
PSTRING str = "abcdefg";
PSTRING sub = "abc";
PSTRING res;
res = String_Insert( str, sub, 3 );
printf( "%s\n", res ); //abcabcdefg
}
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos)
{
int i;
char a;
for(i=0;sub[i]!='0';i++)
{
a=sub[i];
str=Insert(str,a,pos+i);
}
return str;
}
Insert(PSTRING str,char a,int pos) //插入函数,将a插入str字符串的第pos个后面
{
char b,c;
c=b=str[pos];
str[pos]=a;
pos++;
for(;str[pos-1]!='0';pos++)
{
b=str[pos];
str[pos]=c;
c=b;
}
return str;
}
要求编写字符串插入函数String_Insert,将字符串sub插入到字符串str中,插入位置为pos(从0开始)。 展开
3个回答
展开全部
//#if !defined(__EX08_15_H_INCLUDED__)
//#define __EX08_15_H_INCLUDED__
//------------------------------------------------------------------------------
// basic constants
//------------------------------------------------------------------------------
#define FALSE 0
#define TRUE 1
#define MAXSTRLEN 32767
//------------------------------------------------------------------------------
// simple types
//------------------------------------------------------------------------------
typedef int BOOL;
typedef unsigned int POS;
typedef unsigned int COUNT;
typedef int DIR;
typedef char STRING[MAXSTRLEN+1];
typedef char* PSTRING;
//#endif // #if
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos);
PSTRING Insert(PSTRING str,char a,POS pos);
//这个是ex09.c
//#include "ex09.h"
#include <stdio.h>
#include <string.h>
//------------------------------------------------------------------------------
// main function
//------------------------------------------------------------------------------
void main()
{
PSTRING str = "abcdefg";
PSTRING sub = "abc";
STRING res;
strcpy(res, str);
String_Insert( res, sub, 3 );//str指向的是常量,不能被修改。
printf( "%s\n", res ); //abcabcdefg
}
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos)
{
int i;
char a;
for(i=0;sub[i]!=0;i++)//条件错误
{
a=sub[i];
str=Insert(str,a,pos+i);
}
return str;
}
PSTRING Insert(PSTRING str,char a,POS pos) //插入函数,将a插入str字符串的第pos个后面
{
char b,c;
c=b=str[pos];
str[pos]=a;
pos++;
for(;str[pos-1]!=0;pos++)//条件错误
{
b=str[pos];
str[pos]=c;
c=b;
}
str[pos] = 0;
return str;
}
VC6.0编译通过。
//#define __EX08_15_H_INCLUDED__
//------------------------------------------------------------------------------
// basic constants
//------------------------------------------------------------------------------
#define FALSE 0
#define TRUE 1
#define MAXSTRLEN 32767
//------------------------------------------------------------------------------
// simple types
//------------------------------------------------------------------------------
typedef int BOOL;
typedef unsigned int POS;
typedef unsigned int COUNT;
typedef int DIR;
typedef char STRING[MAXSTRLEN+1];
typedef char* PSTRING;
//#endif // #if
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos);
PSTRING Insert(PSTRING str,char a,POS pos);
//这个是ex09.c
//#include "ex09.h"
#include <stdio.h>
#include <string.h>
//------------------------------------------------------------------------------
// main function
//------------------------------------------------------------------------------
void main()
{
PSTRING str = "abcdefg";
PSTRING sub = "abc";
STRING res;
strcpy(res, str);
String_Insert( res, sub, 3 );//str指向的是常量,不能被修改。
printf( "%s\n", res ); //abcabcdefg
}
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos)
{
int i;
char a;
for(i=0;sub[i]!=0;i++)//条件错误
{
a=sub[i];
str=Insert(str,a,pos+i);
}
return str;
}
PSTRING Insert(PSTRING str,char a,POS pos) //插入函数,将a插入str字符串的第pos个后面
{
char b,c;
c=b=str[pos];
str[pos]=a;
pos++;
for(;str[pos-1]!=0;pos++)//条件错误
{
b=str[pos];
str[pos]=c;
c=b;
}
str[pos] = 0;
return str;
}
VC6.0编译通过。
更多追问追答
追问
那个main函数是老师给的,应该没错吧。。。而且他那个str是用双引号赋值的,不算常量吧
追答
PSTRING定义的是个字符指针,指向的是双引号里的字符常量
展开全部
// ex09.h 内容
#if !defined(__EX08_15_H_INCLUDED__)
#define __EX08_15_H_INCLUDED__
//------------------------------------------------------------------------------
// basic constants
//------------------------------------------------------------------------------
#define FALSE 0
#define TRUE 1
#define MAXSTRLEN 32767
//------------------------------------------------------------------------------
// simple types
//------------------------------------------------------------------------------
typedef int BOOL;
typedef unsigned int POS;
typedef unsigned int COUNT;
typedef int DIR;
typedef char STRING[MAXSTRLEN+1];
typedef char* PSTRING;
#endif // #if
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos);
PSTRING Insert(PSTRING str, char a, POS pos)
// ex09.c 内容
#include "ex09.h"
#include <stdio.h>
//------------------------------------------------------------------------------
// main function
//------------------------------------------------------------------------------
int main()
{
PSTRING str = "abcdefg";
PSTRING sub = "abc";
PSTRING res;
res = String_Insert(str, sub, 3);
printf("%s\n", res); //abcabcdefg
return 0;
}
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos)
{
int i;
char a;
for (i=0; sub[i] != '\0'; i++)
{
a = sub[i];
str = Insert(str, a, pos + i);
}
return str;
}
PSTRING Insert(PSTRING str, char a, POS pos)
{
char b, c;
c = b = str[pos];
str[pos] = a;
pos++;
for(; str[pos-1]!='\0'; pos++)
{
b = str[pos];
str[pos] = c;
c = b;
}
return str;
}
追问
大哥,你改哪了。。。。我怎么没看出改动。。
追答
// ex09.h 内容
PSTRING Insert(PSTRING str, char a, POS pos); // 这里忘记加分号了
// ex09.c 内容
#include "ex09.h"
#include <stdio.h>
int main() // 在 VS 2008 以后编译不过, 改为 int main()
{
PSTRING str = "abcdefg";
PSTRING sub = "abc";
PSTRING res;
res = String_Insert(str, sub, 3);
printf("%s\n", res); //abcabcdefg
return 0; // 使用 int main 需要有返回值
}
PSTRING String_Insert(PSTRING str, PSTRING sub, POS pos) // 这里修改了加了返回值类型, 否则编译器认为是返回值为 int 类型, 修改为你自定义 POS 类型, 否则编译器认为类型和函数原型不同
{
int i;
char a;
for (i=0; sub[i] != '\0'; i++) // 这里是判断结束符 '\0', 不是你写的 '0'
{
a = sub[i];
str = Insert(str, a, pos + i);
}
return str;
}
PSTRING Insert(PSTRING str, char a, POS pos)
{
char b, c;
c = b = str[pos];
str[pos] = a;
pos++;
for(; str[pos-1]!='\0'; pos++) // 这里是判断结束符 '\0', 不是你写的 '0'
{
b = str[pos];
str[pos] = c;
c = b;
}
return str;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询