Thread: Salem this for u !

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Salem this for u !

    Can you please tell me how i can change this line ?


    newptr->ID = NUM;
    printf ("%d",NUM);

    newptr->nextptr=(node*)malloc(sizeof(node));
    newptr=newptr->nextptr;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,664
    Like so
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void traverse(void);
    
    /* Structure for printing the id.txt file */
    struct id_card {
        int ID;
        struct id_card *nextptr;
    };
    
    typedef struct id_card node;
    
    void traverse(void) {
        FILE *fp;
        node *currptr = NULL, *headptr = NULL, *prevptr = NULL;
        int NUM, i;
    
        fp = fopen( "id.txt","r" );
        if ( fp == NULL ) {
            printf( "Unabale to open id.txt file \n" );
            exit( 1 );
        }
    
        for(i = 1; i<=8; i++) {
            NUM = getc( fp );
            NUM = NUM-48;
            currptr = malloc( sizeof(node) );
    
            currptr->ID = NUM;
            currptr->nextptr = NULL;
            printf( "%d",NUM );
    
            if ( headptr == NULL ) {
                /* List is empty - start a new list */
                headptr = currptr;
                prevptr = currptr;
            } else {
                /* append to existing list */
                prevptr->nextptr = currptr;
                prevptr = currptr;
            }
        }
    
        currptr = headptr;
        while ( currptr != NULL ) {
            printf( "\n" );
            printf( "%d", currptr->ID );
            currptr=currptr->nextptr;
        }
    
        fclose( fp );
    }
    
    
    int main( ) {
        traverse();
        return 0;
    }

  3. #3
    Unregistered
    Guest
    Thanx Salem the program looks good, but i have one error on


    Line 28 currptr = malloc( sizeof(node) );

    how can i fix it i have a message saying

    cannot assign 'void near' to 'id_card near*' in function

    any idea how i can sot it out ?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > cannot assign 'void near' to 'id_card near*' in function

    Update your compiler. It is old. You shouldn't have "near" and "far" pointers. They have been obsoleted by 32bit integers.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ help needed
    By ettore in forum C++ Programming
    Replies: 17
    Last Post: 01-18-2008, 12:20 PM
  2. Salem - makes it into the news
    By risby in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-22-2006, 07:23 AM
  3. Salem
    By unanimous in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-09-2003, 11:39 AM
  4. GJ Salem
    By Imperito in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 04-09-2002, 10:43 AM
  5. Salem, you might wanna help me
    By Gades in forum C Programming
    Replies: 4
    Last Post: 11-09-2001, 02:57 AM