You can update code to
int read_line(char str[],int n)
{
int ch,i=0;
while((ch = getchar()) != '\n' && ch != EOF){
if(i < n)
str[i++] = ch;
continue;
}
str[i]= '\0';
return i;
}
struct part *insert(struct part *inventory)
{
struct part *student, *first=NULL;
int i=0;
//do the reading in loop, assuming you want to read multiple lines
//as multiple student records.
do {
student = malloc(sizeof(struct part)+1);
i= read_line(student -> name, NAME_LEN);
if(i>0)
{
student ->next = inventory;
if(!first)
first = student;
}
}while(i>0);
return first; //assuming you want to return first instance of record added.
}