struct封装???
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ERRP(con, ret) do{\
if (con)\
{\
ret;\
}\
}while(0)
struct class_t {
char name[128];
int age;
int sex;
int id;
int cn;
int en;
};
int main(void)
{
struct class_t stu;
int i = 10, j = 0;
int count = 0;
struct class_t *p = NULL, *prev = NULL;
/*srand(time(NULL));*/
/*srand(getpid());*/
while(1)
{
printf("please input %d char:", count + 1);
scanf("%c", &ch);
if (ch == 'q')
break;
while(getchar() != '\n');
;
/*printf("%d \n", num);*/
p = (char *)malloc((count + 1) * sizeof(char));
ERRP(NULL == p, return -1);
memmove(p, prev, sizeof(char) * (count));
p[count] = ch;
free(prev);
prev = p;
count++;
}
putchar(10);
for (i = 0; i < count; i++)
{
printf("%c ", p[i]);
}
printf("\n");
free(p);
return 0;
}