Solved

how to correct illegal seek error fo my code.

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How VPC help preventing STP Loops 4 100
SOFS cluser offline 3 52
Unauthorized Network Devices Appearing on Home Network 20 110
VMware ESXi vswitch - performance question 2 46
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…

778 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