Sponsored Content
Full Discussion: Segment Violation
Top Forums Programming Segment Violation Post 302425556 by Corona688 on Friday 28th of May 2010 12:03:49 PM
Old 05-28-2010
The value of pList in main is undefined and probably pointing off into hyperspace somewhere. The instant you try to use it you're trying to access memory you never allocated.

Your logic is also a touch incorrect. An empty list has no memory allocated to it at all in this scheme, hence can't be modified without modifying the base pointer itself, which your function cannot do, being passed only a copy of it.

Pass a pointer to the pointer so it can modify it, check for the special case of creating the first node, and make sure you set the value of the empty list to NULL.

Code:
void insertAtEnd(NodeType **ppList) {
    NodeType *plist=(*ppList);
    char element;

    printf("Introduce a element: \n");
    setbuf(stdin, NULL);
    scanf("%c", &element);

    //Makes a new node.
    NodeType *newNode = (NodeType *) malloc(sizeof(NodeType));
    newNode->caracter = element;
    newNode->nextNode = NULL;

    // Empty list.
    if(plist == NULL)
    {
          // Set the base of the list to the new node
          (*ppList)=plist;
          return;
    }


    //Find the end of the list;
    while (pList->nextNode != NULL) {
        pList = pList->nextNode;
    }

    //Links the new node.
    pList->nextNode = newNode;
}

int main(int argc, char argv[]) {

    NodeTipe *pList=NULL;
    insertAtEnd(&pList); 
}

 

9 More Discussions You Might Find Interesting

1. Programming

Segment Fault

When run it, segment fault. What is wrong? #include <stdio.h> #include <stdlib.h> const int max =20; //**************************************************** // Input Matrix //**************************************************** void inMatrixAA(int *AA, int row, int col)... (9 Replies)
Discussion started by: zhshqzyc
9 Replies

2. Shell Programming and Scripting

extract segment

Hey all, could someone please direct me on how to extract a segment from a file between two tags? Thanks! (1 Reply)
Discussion started by: mpang_
1 Replies

3. Shell Programming and Scripting

Cutting segment of a string

Hi, I am using bash. My question concerns cutting out segments of a string. Given the following filename: S2002254132542.L1A_MLAC.x.hdf I have been able to successfully separate the string at the periods (.): $ L1A_FILE=S2002254132542.L1A_MLAC.x.hdf $ BASE=$(echo $L1A_FILE | awk -F.... (5 Replies)
Discussion started by: msb65
5 Replies

4. UNIX for Dummies Questions & Answers

code segment

how do i close a do code segment? od? (1 Reply)
Discussion started by: trob
1 Replies

5. Shell Programming and Scripting

How to change a segment in a particular position

I need help in removing a leading zero in a particular position. For eg.: XYZ*04567472*0099*020091231*0123*0.12 In the above line, I want to replace "*0123" with "123" and "0.12" with ".12". I want to remove the leading zero only in position number 4 and 5 (the bolded segments) I was able... (10 Replies)
Discussion started by: ananthmm
10 Replies

6. Programming

How can I know where the segment of memory is all Zero?

I mean, I malloc a segment of memory, maybe 1k maybe 20bytes.. assume the pointer is pMem How can I know the content pMem refered is all Zero or \0 . I know memcmp but the second parameter should another memory address... thanx (4 Replies)
Discussion started by: macroideal
4 Replies

7. Programming

Data segment or Text segment

Hi, Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment? char *a = "Hello"; I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
Discussion started by: royalibrahim
7 Replies

8. Programming

why segment fault,

I always get segment fault, why? can sb help me and modify it, I have spend on much time on #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <string.h> #define MAX 10 pthread_t thread; void *thread1() { int *a; int i, n; ... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

9. Shell Programming and Scripting

[Solved] Trimming out segment

I have a file with a combination of binary characters and words, and need to trim out the segment i.e. SleeperThreadAborting {{username::RAB2002}} {{scriptname::scs_get_pending_by_loc}} and put the lists into a text file. Luckily, the segment I am looking for i.e. has readable words ... (8 Replies)
Discussion started by: Daniel Gate
8 Replies
QDomNamedNodeMap(3qt)													     QDomNamedNodeMap(3qt)

NAME
QDomNamedNodeMap - Collection of nodes that can be accessed by name SYNOPSIS
All the functions in this class are reentrant when Qt is built with thread support.</p> #include <qdom.h> Public Members QDomNamedNodeMap () QDomNamedNodeMap ( const QDomNamedNodeMap & n ) QDomNamedNodeMap & operator= ( const QDomNamedNodeMap & n ) bool operator== ( const QDomNamedNodeMap & n ) const bool operator!= ( const QDomNamedNodeMap & n ) const ~QDomNamedNodeMap () QDomNode namedItem ( const QString & name ) const QDomNode setNamedItem ( const QDomNode & newNode ) QDomNode removeNamedItem ( const QString & name ) QDomNode item ( int index ) const QDomNode namedItemNS ( const QString & nsURI, const QString & localName ) const QDomNode setNamedItemNS ( const QDomNode & newNode ) QDomNode removeNamedItemNS ( const QString & nsURI, const QString & localName ) uint length () const uint count () const bool contains ( const QString & name ) const DESCRIPTION
The QDomNamedNodeMap class contains a collection of nodes that can be accessed by name. Note that QDomNamedNodeMap does not inherit from QDomNodeList. QDomNamedNodeMaps do not provide any specific node ordering. Although nodes in a QDomNamedNodeMap may be accessed by an ordinal index, this is simply to allow a convenient enumeration of the contents of a QDomNamedNodeMap, and does not imply that the DOM specifies an ordering of the nodes. The QDomNamedNodeMap is used in three places: <ol type=1> 1 QDomDocumentType::entities() returns a map of all entities described in the DTD. 2 QDomDocumentType::notations() returns a map of all notations described in the DTD. 3 QDomNode::attributes() returns a map of all attributes of an element. Items in the map are identified by the name which QDomNode::name() returns. Nodes are retrieved using namedItem(), namedItemNS() or item(). New nodes are inserted with setNamedItem() or setNamedItemNS() and removed with removeNamedItem() or removeNamedItemNS(). Use contains() to see if an item with the given name is in the named node map. The number of items is returned by length(). Terminology: in this class we use "item" and "node" interchangeably. See also XML. MEMBER FUNCTION DOCUMENTATION
QDomNamedNodeMap::QDomNamedNodeMap () Constructs an empty named node map. QDomNamedNodeMap::QDomNamedNodeMap ( const QDomNamedNodeMap & n ) Constructs a copy of n. QDomNamedNodeMap::~QDomNamedNodeMap () Destroys the object and frees its resources. bool QDomNamedNodeMap::contains ( const QString & name ) const Returns TRUE if the map contains a node called name; otherwise returns FALSE. uint QDomNamedNodeMap::count () const Returns the number of nodes in the map. This function is the same as length(). QDomNode QDomNamedNodeMap::item ( int index ) const Retrieves the node at position index. This can be used to iterate over the map. Note that the nodes in the map are ordered arbitrarily. See also length(). uint QDomNamedNodeMap::length () const Returns the number of nodes in the map. See also item(). QDomNode QDomNamedNodeMap::namedItem ( const QString & name ) const Returns the node called name. If the named node map does not contain such a node, a null node is returned. A node's name is the name returned by QDomNode::nodeName(). See also setNamedItem() and namedItemNS(). QDomNode QDomNamedNodeMap::namedItemNS ( const QString & nsURI, const QString & localName ) const Returns the node associated with the local name localName and the namespace URI nsURI. If the map does not contain such a node, a null node is returned. See also setNamedItemNS() and namedItem(). bool QDomNamedNodeMap::operator!= ( const QDomNamedNodeMap & n ) const Returns TRUE if n and this named node map are not equal; otherwise returns FALSE. QDomNamedNodeMap &; QDomNamedNodeMap::operator= ( const QDomNamedNodeMap & n ) Assigns n to this named node map. bool QDomNamedNodeMap::operator== ( const QDomNamedNodeMap & n ) const Returns TRUE if n and this named node map are equal; otherwise returns FALSE. QDomNode QDomNamedNodeMap::removeNamedItem ( const QString & name ) Removes the node called name from the map. The function returns the removed node or a null node if the map did not contain a node called name. See also setNamedItem(), namedItem(), and removeNamedItemNS(). QDomNode QDomNamedNodeMap::removeNamedItemNS ( const QString & nsURI, const QString & localName ) Removes the node with the local name localName and the namespace URI nsURI from the map. The function returns the removed node or a null node if the map did not contain a node with the local name localName and the namespace URI nsURI. See also setNamedItemNS(), namedItemNS(), and removeNamedItem(). QDomNode QDomNamedNodeMap::setNamedItem ( const QDomNode & newNode ) Inserts the node newNode into the named node map. The name used by the map is the node name of newNode as returned by QDomNode::nodeName(). If the new node replaces an existing node, i.e. the map contains a node with the same name, the replaced node is returned. See also namedItem(), removeNamedItem(), and setNamedItemNS(). QDomNode QDomNamedNodeMap::setNamedItemNS ( const QDomNode & newNode ) Inserts the node newNode in the map. If a node with the same namespace URI and the same local name already exists in the map, it is replaced by newNode. If the new node replaces an existing node, the replaced node is returned. See also namedItemNS(), removeNamedItemNS(), and setNamedItem(). SEE ALSO
http://doc.trolltech.com/qdomnamednodemap.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qdomnamednodemap.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QDomNamedNodeMap(3qt)
All times are GMT -4. The time now is 10:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy