Solved

how to correct illegal seek error fo my code.

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HP network exams 3 58
Question about Buffalo NAS devices 4 51
Cannot join domain and UNC paths 9 52
Port status messages not appearing in console 11 32
Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

749 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