#include<stdio.h>#include<string.h>#define TSIZE 45#define FMAX 5structfilm{char title[TSIZE];
int rating;
};
char *s_gets(char *st, int lim);
intmain(){
structfilmmovies[FMAX];int i = 0;
int j;
puts("Enter first movie tile:");
while (i < FMAX && s_gets(movies[i].title ,TSIZE) != NULL && movies[i].title[0] != '\0')
{
puts("Enter your rating <0 -10>:");
scanf("%d", &movies[i++].rating);
while (getchar() != '\n')
continue;
puts("Enter next movie title (empty line to stop)");
}
if (i == 0)
printf("no data entered.");
elseprintf("here is the movie list:\n");
for (j=0; j < i; j++)
{
printf("movie title: %s movie rating: %d \n", movies[j].title, movies[j].rating);
}
printf("ByeBye!!");
return0;
}
char *s_gets(char *st, int lim){
char *find;
if(fgets(st, lim, stdin))
{
find = strchr(st, '\n');
if(find)
*find = '\0';
elsewhile(getchar()!='\n')
continue;
}
return st;
}