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;
}