I have a bit of an issue. I'll explain, I'm trying to create a dynamic memory allocation for a string inside a struct and print it. The thing is, it doesn't care about the size I dynamically allocate.
For example, I create a string in the size of size 6, but it let's me insert 15 chars and prints them all.
So basically, it doesn't limit me on the string size, why's so?
typedef struct{
int grade;
int id;
int arr[5];
char *str;
}student;
int main(){
puts("How many many letters in char?\n");
scanf("%d", &num);
getchar();
student1.str = (char *)malloc(sizeof(char)*num+1);
gets(buffer);
strcopy(student1.str, buffer);
}
BTW, I tried to keep the code clear as possible for you guys/ladies, just with the main things I need. I know I didn't free the memory or checked if allocation failed etc...