Solved

how to correct illegal seek error fo my code.

Posted on 2003-11-07
3
768 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SD - WAN 2 45
Tagging ports on a managed switch 6 52
Creating and Connection two new domains 5 79
slow vpn connection 9 42
Some time ago I was asked to set up a web portal PC to put at our entrance. When customers arrive, they could see a webpage 'promoting' our company. So I tried to set up a windows 7 PC as a kiosk PC.......... I will spare you all the annoyances I…
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now