c语言typedef怎么自定义函数,C语言函数内部可以使用typedef么?解决方案

C/C++ code#ifndef _TYPE_SELEMTYPE

#define _TYPE_SELEMTYPE

typedef char SElemType;

#endif

typedef SElemType * ElemLink;

#include

#include

#include

#include "../SqStack_use.h" //栈的存储结构

#include "../SqStack_ops.c" //栈的基本操作

//Status 在SqStack_use.h文件中有定义

Status IsParentheses ( char left, char right ); //判断是否匹配

Status parenthesesMatch ( char *str );

Status parenthesesMatch ( char *str )

{

SqStack S;

SElemType e;

ElemLink p;

int len;

int i;

InitStack_Sq(&S); //此函数在SqStack_ops.c中

len = strlen(str);

p = NULL;

for ( i=0; i

Push_Sq(&S,*(str+i));

if (p!=NULL && IsParentheses(*p, *(S.top-1)) == YES) {

Pop_Sq(&S, &e);

Pop_Sq(&S, &e);

}

p = S.top-1;

}

if (StackEmpty_Sq(S) == YES)

return YES;

else

return NO;

}

Status IsParentheses ( char left, char right )

{

if (left=='(' && right==')')

return YES;

else if (left=='[' && right==']')

return YES;

else if (left=='{' && right=='}')

return YES;

else

return NO;

}

int main ( int argc, char *argv[] )

{

char str[20];

do {

printf ( "==========================\n" );

printf ( "intput some parentheses(input one char to exit):\n" );

scanf("%s", str);

if (strlen(str) == 1)

break;

#ifdef _TYPE_SELEMTYPE

typedef float SElemType;

SElemType num = 100.01;

printf ( "num is :%f\n" , num);

#endif

//我这样用了,不知道对不对,但是编译通过了,请各位指教啊

if (parenthesesMatch(str) == YES)

printf ( "parentheses matching! congratulations!\n" );

else

printf ( "sorry parentheses not matching!\n" );

} while (1);

return EXIT_SUCCESS;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值