#include<stdio.h>
    #include<string.h>
    typedef struct
    { char name[20];
    long int ptn;
    float lt;
    }census;
    int main()
    { int i,n;
    census city[10];
    printf("How many cities\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    census city[10];
    printf("Name:");
    gets(city[i].name);
    printf("\nPopulation:");
    scanf("%ld",&city[i].ptn);
    printf("\nlteracy:");
    scanf("%f",&city[i].lt);
    }
    }
  1. You declare "census city[10];" within the loop while it's also declared outside of it..
  2. The issue is similar to your other thread. See my awnser there: http://www.daniweb.com/software-development/c/threads/437105/scanf-is-skipping-in-last-input-.-if-i-use-int-instead-of-charcode-is-runn
  3. Use fgets() instead of gets().

Summary of the problem: With the first scanf a newline remains in the stream. gets() stops when reading a newline which is the first thing it reads now because it was left in the stream as mentioned.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.