0

I have written this program as described in Walkthrough week 4 in structs 0 but it is not working, Kindly point out the mistake Thanks a lot.

# include <stdio.h>
# include <cs50.h>
# include "struct.h"
# define STD 3
int main (void)
{
    student students[STD];
    int i=0;
    for (i=0;i<STD;i++)

    {
        printf("enter name\n");
        students[i].name= GetString();
        printf("Adress\n");
        students[i].house = GetString();

    }
        for (int y=0;y<STD;y++)
        {
        printf("students name is %s lives in %s\n\n", students[i].name, students[i].house);
        }
        for (int x=0;x<STD;x++)
    {    
        free (students[i].name);
        free (students[i].house);

    }

}

1 Answer 1

1

You are always using the subscript 'i'. 'i' has the value 3 when the first loop is finished. You can either change the subscript names in the y loop and the x loop OR just use 'i' again to run those loops.

1
  • Yap I found this mistake just after posting this question, Thanks for the reply
    – Ahmed Raza
    Commented Nov 15, 2016 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .