I am trying to create a structure. reads a name and stores it to a variable in the structure and then print it. Sounds simple enough. Look at the ouput i got. I am so lost its not even funny...
My code is below... can someone help me with this...
I think this is a pointer issue.. but i am not sure...
Code:
E:\COMMAN~1>gcc st.c -o st.exe -std=c99 E:\COMMAN~1>st on NTVDM, specify an inval on NTVDM, specify an inval Name: on NTVDM, specify an inval Name: on NTVDM, specify an inval Name: n NTVDM, specify an inval Name: NTVDM, specify an inval Name: NTVDM, specify an inval Name: TVDM, specify an inval Name: VDM, specify an inval Name: DM, specify an inval Name: M, specify an inval Name: , specify an inval Name: specify an inval Name: specify an inval Name: pecify an inval Name: ecify an inval Name: cify an inval Name: ify an inval Name: fy an inval Name: y an inval Name: an inval Name: an inval Name: n inval Name: inval Name: inval Name: nval Name: val Name: al Name: l
Code:
typedef struct
{
char name[30];
} Student; // name of structure
int myStruct_set_values(Student* s, char data[30])
{
for(int i=0;i<29;i++)
{
s -> name[i] = data[i];
}
}
int main()
{
Student sOne;
Student* st_ptr = &sOne;
char input[30];
myStruct_set_values(st_ptr, input);
sscanf("%s",input);
for(int i=0;i<29;i++)
{
printf(" \n Name: %s", &st_ptr -> name[i]);
}
}
Comment