Solved

how to correct illegal seek error fo my code.

Posted on 2003-11-07
3
767 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
Comment Utility
>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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
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…

763 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

10 Experts available now in Live!

Get 1:1 Help Now