0

This program when it receives the input 1, it receives info from the user and if the input 2 is given it shows what it has stored so far.

The issue is that when you select 2 after having inserted the required info, the name that was provided appears as NULL.

1
  • No &: scanf("%[^\n]%*c", OE1); -- OE1 is an array; it gets automatically converted to a pointer (to its first element) when used as argument in scanf() function.
    – pmg
    Commented Feb 25, 2022 at 17:56

1 Answer 1

1

Instead of

scanf("%[^\n]%*c", &OE1);
                  ^^^  

you need to write

scanf("%[^\n]%*c", OE1);

This statement

ptr -> OE[NAME_LEN]=OE1[NAME_LEN];

does not make a sense.

You need to write

#include <string.h>

//...

strcpy( ptr -> OE, OE1 );

This functionality of this if statement

   if(head==NULL)
     ptr->next=NULL;
   else
     ptr->next=head;

can be performed just by one statement

ptr->next = head;

And this statement

printf("%d     %s    %d\n",ptr->AM, ptr->OE[NAME_LEN], ptr->XS);

must be substituted for this one

printf("%d     %s    %d\n",ptr->AM, ptr->OE, ptr->XS);
1
  • @user17850871 I am sorry I have not understood what you mean. Commented Feb 25, 2022 at 20:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.