Solved

how to correct illegal seek error fo my code.

Posted on 2003-11-07
3
783 Views
Last Modified: 2008-03-03
in my programm i m just trying to store the information using linklist. but when i m trying to display(using user defined display)  it i m getting
illegal seek error. please modify the code to correct  the error as soon as possible.

C code is as follows.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
struct emp
{
      int info;
      char name[20];
      char add[30];
      int sal;
      struct emp *next;
};
typedef struct emp node;
void append (node *);
void display(node *);
node *start;
main()
{
       int n,i;
       clrscr();
       start=(node *)malloc(sizeof(node*));
      // printf("\nSTART : %d",start);
       append(start);
}

void append(node *record)
{

      char naam[20];
      //printf("\n RECORD %d",record);
      //printf("\n RECORD->NEXT : %d",record->next);
      printf("\n Enter the element(type 0 when finished):");
      scanf("%d",&record->info);
      printf("\n Enter the name :");
      scanf("%s",record->name);
      fflush(stdin);
      printf("\nEnter the address:");
      scanf("%s",record->add);
      printf("\nEnter Salary:");
      scanf("%d",&record->sal);
      record->next = (node *)malloc (sizeof(node *));

      if(record->info==0)
                  record->next=NULL;
      else
      {
            append(record->next);
            return;
      }

      display(start);
      return;


}

void display(node *record)
{

      if(record->next!=NULL)

      {
        //      printf("\n RECORD->NEXT : %d",record->next);
            printf("\n INFO IS : %d",record->info);
            printf("\n Name    : %s",record->name);
            printf("\n Address : %s",record->add);
            printf("\n Salary  : %d",record->sal);
            display(record->next);


      }
      return;

}





0
Comment
Question by:kaushikritu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 50 total points
ID: 9700175
>start=(node *)malloc(sizeof(node*));

you allocate memory for a single node * and try to store a node in it !!!
this should be
start=(node *)malloc(sizeof(node));


>record->next = (node *)malloc (sizeof(node *));

>    if(record->info==0)
>              record->next=NULL;

will cause a memory leak !!! ... redefine it to

    if(record->info==0)
              record->next=NULL;
    else {
              record->next = (node *)malloc (sizeof(node *));
              append(record->next);
               return;
       }

>void display(node *record)
>{

>    if(record->next!=NULL)
should be
void display(node *record)
{

    if(record!=NULL)

also, this will be a better place to ask such questions
http://www.experts-exchange.com/Programming/Programming_Languages/C/
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question