Sponsored Content
Full Discussion: Bus Error: 10...Help please!
Top Forums Programming Bus Error: 10...Help please! Post 302772022 by Corona688 on Friday 22nd of February 2013 12:42:58 PM
Old 02-22-2013
My suggestion would be to build functions to separate your linked list from your input code.

Code:
NODE *create_node(const char *name, const char *num, NODE *prev, NODE *next)
{
        int n;

        NODE *mem=malloc(sizeof(NODE));
        if(mem == NULL) return(NULL);

        strncpy(mem->number, num, sizeof(mem->number));
        mem->number[sizeof(mem->number)-1]='\0';

        strncpy(mem->name, name, sizeof(mem->name));
        mem->name[sizeof(mem->name)-1]='\0';
        for(n=0; mem->name[n] != '\0'; n++)
                mem->name[n]=topper(mem->name[n]);

        mem->next=next;
        mem->prev=prev;
        return(mem);
}

void insert(NODE *node)
{
        node *h=head;

        if(h == NULL) // List is empty, just set it to this node
        {
                head=node;
                return;
        }

        // Loop until the end of the list,
        // but STOP at the last one.  h will not be NULL after this loop.
        while(h -> next != NULL)
        {
                int v=strcmp(node->name, h->name);

                if(v == 0) return; // Reject duplicate
                else if(v < 0)
                {
                        h=h->next;
                        continue;
                }

                // We want to change a <-> b <-> d <-> e into
                // a <-> b <-> c <-> d <-> e
                // We are at node d.

                // point ahead to d
                node->next=h;
                // point back to b
                node->prev=h->prev;

                // make b point ahead to us
                if(h->prev != NULL) h->prev->next=node;
                // make d point back to us
                h->prev=node;

                return;
        }

        if(h->next == NULL) // append to list
        {
                h->next=node;
                node->prev=h;
                return;
        }
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Bus Error

This may belong in the C Programming forum, but here goes anyway... What would cause a bus error? I searched google for a cause, but came up with some conflicting reports... Could it be caused by disk space? A lot of the pages I found mentioned linking with the incorrect versions of the... (4 Replies)
Discussion started by: LivinFree
4 Replies

2. UNIX for Dummies Questions & Answers

bus error on solaris

Hi there I am running soalris 9 on a sun fire 480r and all of a sudden (today) whenever the users run the command `top` we get the following message `bus error` does anybody have any information on what this is all about and whether there is a routine i can perform to gather more... (3 Replies)
Discussion started by: hcclnoodles
3 Replies

3. UNIX for Dummies Questions & Answers

Bus error(coredump

aix 5.3 ML1 system was functioing well, when suddenly telnet session hung and then I got the following message "Bus error(coredump)" would appreciate if anyone would assist as to what to do next. (3 Replies)
Discussion started by: Student37
3 Replies

4. UNIX for Advanced & Expert Users

Bus Error(coredump)

Hi, I am using HP-UX. While i try to run the Sqlplus command using the shel script in encounter the following error: <shell script name>: some number Bus Error(coredump) What may be the reason behind this. I read few previous threads in this forum where i found some similar case. There it was... (2 Replies)
Discussion started by: Jayesh
2 Replies

5. Programming

BUS error

Hi! I've got a program which runs fine under Linux, but I have compiled it to run under SunOS 5.8 in a Sparc computer, and now it sometimes fails with "bus error". Ussing gdb I surfed to the error line, which is *pointer = some_vector; where some_vector is a 16 byte struct (4 integers)... (1 Reply)
Discussion started by: shesatmine
1 Replies

6. UNIX for Dummies Questions & Answers

bus error (coredump)

Hi all, I am getting bus error problem in SunOS. Can you please help me out in this regard. Actually, my entire code till the last line has been executed. But after tht i am getting a bus error. Please help me. Thanks in advance. Charu. (4 Replies)
Discussion started by: charu
4 Replies

7. HP-UX

Need help on Bus error(coredump)

Hi all, I am quite weak in C but I need to get some work done. Hope someone can help me out. I keep getting this error when i try to run my C application in my HP-UX 10.20 machine. Some code snippet: Month(DBTime) =====This is a function which will return variable "CutOffTime" to be use... (5 Replies)
Discussion started by: Vision©
5 Replies

8. HP-UX

Bus Error

I am getting bus error when i include "#!/bin/ksh". If i remove interpreter then script is working. Can anyone explain this and how can i avoid this error? Operating System is HP-UX B.11.23 U 9000/800 1091834454 (2 Replies)
Discussion started by: anbu23
2 Replies

9. Programming

Bus error

Hi everyone, I have a GUI project and when I run it and left in idle state for a long time(there is nothing done, just opened GUI, no more actions),I get bus error after trying to do anything with it. I've tried to build it in debug mode and use gdb, but I don't get any error in debug mode.It... (3 Replies)
Discussion started by: sisi
3 Replies

10. Programming

Bus error in tree insertion

Hi, I am new to C++ and unix. I am trying to write a programm for inserting elements into a binary tree. To get the code flow I used few Couts and m facing buss error while insertion. Below is the code snippet. explainations needed. thanks :) #include <iostream.h> struct mytree { int... (1 Reply)
Discussion started by: vineetjoshi
1 Replies
MEM(4)							     Linux Programmer's Manual							    MEM(4)

NAME
mem, kmem, port - system memory, kernel memory and system ports DESCRIPTION
mem is a character device file that is an image of the main memory of the computer. It may be used, for example, to examine (and even patch) the system. Byte addresses in mem are interpreted as physical memory addresses. References to nonexistent locations cause errors to be returned. Examining and patching is likely to lead to unexpected results when read-only or write-only bits are present. It is typically created by: mknod -m 660 /dev/mem c 1 1 chown root:kmem /dev/mem The file kmem is the same as mem, except that the kernel virtual memory rather than physical memory is accessed. It is typically created by: mknod -m 640 /dev/kmem c 1 2 chown root:kmem /dev/kmem port is similar to mem, but the I/O ports are accessed. It is typically created by: mknod -m 660 /dev/port c 1 4 chown root:mem /dev/port FILES
/dev/mem /dev/kmem /dev/port SEE ALSO
chown(1), mknod(1), ioperm(2) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 1992-11-21 MEM(4)
All times are GMT -4. The time now is 07:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy