69,373
社区成员
发帖
与我相关
我的任务
分享
#ifndef _TYPE_SELEMTYPE
#define _TYPE_SELEMTYPE
typedef char SElemType;
#endif
typedef SElemType * ElemLink;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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<len; 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;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct example_st {
int what_the_fuck_are_you_doing;
int what_the_fuck_are_you_saying;
int what_the_fuck_are_you_playing;
}*example_t;
example_t init_example() {
example_t p = (example_t)malloc(sizeof(struct example_st));
if (p == NULL) {
return NULL;
}
#define VARIABLE(last_word) p->what_the_fuck_are_you_##last_word
VARIABLE(doing) = 0;
VARIABLE(saying) = 1;
VARIABLE(playing) = 2;
#undef VARIABLE
return p;
}
int main(int argc, char* const argv[]) {
example_t p = init_example();
if (p) {
free(p);
}
return 0;
}
[User:root Time:12:29:30 Path:/home/liangdong/c]$ ./output
10.000000
[User:root Time:12:29:31 Path:/home/liangdong/c]$ cat src/main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int Integer;
void function() {
typedef double Integer;
Integer n = 10;
printf("%lf\n", n);
}
int main(int argc, char* const argv[]) {
function();
return 0;
}