70,024
社区成员




#include <stdio.h>
#include <string.h>
char * s_gets(char * st, int n);
#define MAXTITL 40
#define PHONE 20
#define NUM 50
struct people {
char name[MAXTITL];
int phone[PHONE];
};
int main()
{
struct people list[NUM];
int count = 0;
int index;
printf("please enter the name:");
while (count < MAXTITL && s_gets(list[count].name , MAXTITL) != NULL && list[count].name[0] != '\0')
{
printf("now please enter the phone number:");
s_gets(list[count].phone , PHONE);
while (getchar() != '\n')
continue;
if (count < NUM)
printf("enter the next title.\n");
}
if (count < 0)
{
printf("here is the list of yours:\n");
for (index = 0; index < count; index++)
printf("%s : %d", list[index].name, list[index].phone);
}
else
printf("no man, no number!");
return 0;
}
char *s_gets(char * st, int n)
{
char * ret_val;
char * find;
ret_val = fgets(st, n, stdin);
if (ret_val)
{
find = strchr(st, '\n');
if (find)
*find = '\0';
else
while (getchar() != '\n')
continue;
}
return ret_val;
}
#include <stdio.h>
#include <string.h>
#define MAXTITL 40
#define PHONE 20
#define NUM 50
struct people {
char name[MAXTITL];
char phone[PHONE];
};
char * s_gets(char * st, int n);
int main()
{
struct people list[NUM];
int count = 0;
int index;
printf("please enter the name:");
while (count < MAXTITL && s_gets(list[count].name , MAXTITL) != NULL && list[count].name[0] != '\0')
{
printf("now please enter the phone number:");
s_gets(list[count].phone , PHONE);
while (getchar() != '\n')
continue;
if (count < NUM)
printf("enter the next title.\n");
}
if (count < 0)
{
printf("here is the list of yours:\n");
for (index = 0; index < count; index++)
printf("%s : %s", list[index].name, list[index].phone);
}
else
printf("no man, no number!");
return 0;
}
char *s_gets(char * st, int n)
{
char * ret_val;
char * find;
ret_val = fgets(st, n, stdin);
if (ret_val)
{
find = strchr(st, '\n');
if (find)
*find = '\0';
else
while (getchar() != '\n')
continue;
}
return ret_val;
}