When you asked this question earlier this morning (
please help about linked list in c[
^]) I told you what you need to do.
Ok, I'll try a little more detail.
The
scanf_s
function returns a value, which tells you how it all worked.
If it converted numbers, then it returns the count of the numbers converted. So, if the user enters a single number which matches your format, it will return 1.
If the user enters data which does not match your format, it will return EOF.
Your
input_node
function also returns a value - currently, it is always 0.
What I would do is make
input_node
return true (i.e. nonzero) if the conversion succeeded, and false (i.e. zero) if it failed:
All this needs is to change your routine to:
int input_node(int* pNum, int nFlag)
{
printf("*%s : ", (nFlag == 1)?"Input Value":"Want to delete Value");
return (scanf_s("%d", pNum) != EOF);
}
You can then check this return value when you call your function, and if it is false there is no number so you need to print your message.
if (!input_node(&nData, 1))
{
printf("Error : Input value is invalid");
}
else
{
...
BTW: Well done on adding the comments - but try to make them describe what the code is trying to achieve, not what the C language instruction is doing.
For example:
ptr = ptr->next;
Is better as
ptr = ptr->next;