33,311
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <stdio.h>
#include <string>
struct book
{
int id;
char title[20];
};
struct book item[10];
int _tmain(int argc, _TCHAR* argv[])
{
int l=0;
puts("input the book title");
while(*gets(item[l].title) != 32) //判断空格,如果输入为一个空格就停止...
{
item[l].id=l+1;
l++;
}
int k=0;
while(k<l)
{
printf("id is%d,",item[k].id);
printf("内容是%s \n",item[k].title);
k++;
}
return 0;
}
//空格也算啊,没法那样区分,用数字直接控制大小也行。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM_SIZE 10
#define MAXSIZE 20
struct book
{
int id;
char title[MAXSIZE];
};
void main( void )
{
int i = 0,k = 0;
struct book item[NUM_SIZE];
puts("input the book title");
do
{
gets(item[i].title);
item[i].id=i+1;
i++;
}while(i<NUM_SIZE);
while(k < i)
{
printf("id is%d,",item[k].id);
printf("内容是%s \n",item[k].title);
k++;
}
system("pause");
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM_SIZE 10
#define MAXSIZE 20
struct book
{
int id;
char title[MAXSIZE];
};
void main( void )
{
int i = 0,k = 0;
struct book item[NUM_SIZE];
puts("input the book title");
while( gets(item[i].title),strcmp(item[i].title,"") !=0 )
{
item[i].id=i+1;
i++;
}
while(k < i)
{
printf("id is%d,",item[k].id);
printf("内容是%s \n",item[k].title);
k++;
}
system("pause");
}
测试结果://多点一次回车
input the book title
123+回车
456+回车
789+回车
+回车
id is1,内容是123
id is2,内容是456
id is3,内容是789
请按任意键继续. . .