+ 2

I am using gets() in 'for' loop, but it does not take the user's input. Any solution, thanks in advance.

7th Jul 2020, 2:05 PM
Pankaj Kumar
Pankaj Kumar - avatar
4 Réponses
+ 3
Hi! I played around with your code. Please take a look. Technical details were well explained by Martin Taylor. https://code.sololearn.com/c3gz4mYFdG0Z/?ref=app
9th Jul 2020, 12:29 AM
Vasile Eftodii
Vasile Eftodii - avatar
+ 3
It will be great if you share your code
7th Jul 2020, 2:13 PM
Shobhith J B
Shobhith J B - avatar
+ 1
#include<stdio.h> #include<string.h> main() { int i,numMovies,rating,favRating,leastRating; char movieName[40]; char fav[40],least[40]; favRating=0; leastRating=10; do { printf("how many movies did you watch in last one year\n"); scanf("%d",&numMovies); if(numMovies<1) { printf("you didn't watch any movies how you rate them\n"); printf("try again\n"); } }while(numMovies<1); for(i=0;i<numMovies;i++) { puts("enter the movie name"); gets(movieName); printf("rate this movie\n"); scanf("%d",&rating); if(rating<favRating) { strcpy(fav,movieName); favRating=rating; } if(rating>leastRating) { strcpy(least,movieName); leastRating=rating; } } printf("your favourite movie is %s",fav); printf("your least favourite movie is %s,least"); return (0); }
7th Jul 2020, 4:01 PM
Pankaj Kumar
Pankaj Kumar - avatar