函数的结构体指针参数传递的问题 都忘完了

memset
  <memory.h>   or   <string.h>

void swap(int *p1,int *p2)
{
*p1=5;*p2=6;
}
...
int a=3,b=4;
int *pa=&a,*pb=&b;
swap(pa,pb); //或者swap(&a,&b);


struct   student{
        char   *last_name;
        int     student_id;
        char   grade;
}

struct   student   temp,   *p   =   &temp;
temp.grade   =   'A ';
temp.last_name   =   "Bushker ";
temp.student_id   =   590017;

其中
temp.grade   等价于   p-> grade.值是A
temp.last_name   等价于   p-> last_name.值是Bushker
temp.student_id   等价于   p-> student_id.值是590017
(*p).grade   等价于   p-> student_id.值是590017

这样看来,-> 用于结构指针指向的结构的成员.而结构实体用.指向成员.是这样理解对吧?


#include"stdio.h"
#include"string.h"
#define Max 100
typedef struct{
	char data[Max];
	int top;
}SqStack;

void zhikong(SqStack *s){      //将栈置空.
	s->top=-1;
	memset(s->data,0,100);
}

int push(SqStack *s, char e){  //进栈
	if(s->top==Max-1){
		printf("栈满\n");
		return 0;
	}
	s->top++;
	s->data[s->top]=e;
	return 1;
}
int pop(SqStack *s, char *e){   //出栈
	if(s->top==-1){
		printf("栈空\n");
		return 0;
	}
	*e=s->data[s->top--];
	return 1;
}

int judge(char a[]){      //判断是否是对称串
	int i;
	char e;
	SqStack s;
	zhikong(&s);
	for(i = 0; a[i]!='\n'; i++){
		push(&s,a[i]);
	}
	for(i = 0;a[i]!='\n';i++){
		pop(&s,&e);
		if(a[i]!=e)
			return 0;
	}
	return 1;
}


int main(){

	char a[Max]="";
	int i=-1,n;
	do{
		i++;
		scanf("%c",&a[i]);		
	}while(a[i]!='\n');
	n=judge(a);
	if(n==1)
		printf("该字符串为对称串\n");
	else
		printf("该字符串不为对称串\n");
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值