+ 1

whats wrong in my code not giving desire output in vs code

https://code.sololearn.com/c04t633HwZzr/#c

26th Oct 2021, 5:19 PM
Aman Prasad
Aman Prasad - avatar
3 ответов
+ 2
Maybe because you define int n; struct emp employ[n],*ptr; in line 11 und 12. But you get the input for n at line 15. I would say, that's to late.
26th Oct 2021, 5:33 PM
Coding Cat
Coding Cat - avatar
+ 1
As near as I can tell you're trying to read into memory that you've used malloc() to allocate, and then you're trying to copy what you've read into an array. First I'd pick a single approach. Either make sure the array is sized right (see Coding Cat 's suggestion) and just read directly into that, or don't have the array at all and just malloc() enough memory for n instances of your struct - and use ptr just like you'd use an array.
26th Oct 2021, 7:13 PM
Steve
Steve - avatar
+ 1
thank you sir.
27th Oct 2021, 4:52 PM
Aman Prasad
Aman Prasad - avatar