c - fgets not waiting for user input -


in given code fgets not waiting input.

i tried using scanf it's giving unusual error(exception thrown @ 0x0f74ddf4 (ucrtbased.dll)). i'm using visual studio 2015 debugging code. can explain why fgets not waiting input?

#include<stdio.h> #include<stdlib.h> #include<process.h>  //global-variable declartion #define max 1000  //global-structures declaration struct census { char city[max]; long int p; float l; };  //global-structure-variable declaration struct census cen[] = { 0,0,0 };  //user-defined function void header();  void header() { printf("*-*-*-*-*census_info*-*-*-*-*"); printf("\n\n"); }  //program starts here main() {    //variable-declaration int = 0, j = 0; //int no_of_records = 0;  //function call-out header();  printf("enter no. of city : "); scanf_s("%d", &j);  printf("\n\n");  printf("enter name of city, population , literacy level"); printf("\n\n");  (i = 0;i < j;i++) {     printf("city no. %d - info :", + 1);     printf("\n\n");      printf("city name :");     fgets(cen[i].city, max, stdin);     printf("\n");      printf("population : ");     scanf_s("%d", &cen[i].p);     printf("\n");      printf("literacy : ");     scanf_s("%f", &cen[i].l);     printf("\n"); }  //terminal-pause system("pause"); } 

i use fgets followed sscanf.

declare @ top,

char line[max]; 

then use fgets line, , sscanf parse int value out of it,

printf("enter no. of city : "); fgets(line, sizeof(line), stdin); sscanf(line, "%d", &j); 

similar pattern l

printf("literacy : "); fgets(line, sizeof(line), stdin); sscanf(line, "%f", &cen[i].l); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -