09/01/05 01:53:41
>>199
/* ちょっと気持ち悪く書いてみたよ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ENTER_MAX 10
#define NAME_LEN 256
#define AGE_LEN 4
#define BUFF_SIZE (NAME_LEN + AGE_LEN + 1)
int main(void)
{
char table[ENTER_MAX][BUFF_SIZE];
char buff[BUFF_SIZE];
int n;
int i;
do {
printf("登録数 (1 から %d) >> ", ENTER_MAX);
} while ((n = atoi(fgets(buff, BUFF_SIZE, stdin))) > ENTER_MAX);
for (i = 0; i < n; ++i) {
int len;
printf("名前 >> "); fgets(table[i], NAME_LEN, stdin);
len = strlen(table[i]);
printf("年齢 >> "); fgets(&table[i][len + 1], AGE_LEN, stdin);
table[i][len - 1] = ','; table[i][len] = ' ';
}
for (i = 0; i < n; ++i) printf("%s", table[i]);
return 0;
}