Thread: linked list help

  1. #1
    Unregistered
    Guest

    linked list help

    The following prog reads in a MIPS assembly prog and numbers the lines !=NULL and writes all lines including NULL to another file. NOW what i want to do is to look at each line and look for assembly Identifiers,(these can start with a underscore, a cap or lowercase letter or a digit.)and put them into a linked list each node of the list should contain 2 fields one for line number and one for the identifier I think my struct should look something like
    struct node {
    int line_number
    char identifier
    struct node *next


    anyway heres what i have so far
    #include <stdio.h>
    #include <string.h>

    #define MAXLEN 81
    #define NUMARG 3



    int main (int argc, char *argv[])
    {
    char buffer[MAXLEN];
    FILE *finp, *foutp;
    unsigned int line_number=0;
    if (argc != NUMARG)
    {
    printf("usage : p2 infile outfile -m -u\n");
    exit (1);
    }

    if ((finp = fopen(argv[1], "r")) == NULL)
    {
    printf("could not open file %s for reading. \n", argv[1]);
    exit (1);
    }

    if ((foutp =fopen(argv[2], "w")) == NULL)
    {
    printf("could not open file %s for writing.\n", argv[2]);
    exit(1);
    }
    /* count non empty lines */
    /*output all lines*/
    while (fgets(buffer, sizeof (buffer), finp))
    {
    if(strlen(buffer)>1)
    if(fprintf(foutp, "%u", ++line_number)<=0)
    break;

    if(fprintf(foutp, "%s",buffer)<=0)
    break;
    }



    if (fclose(finp) == EOF)
    {
    printf("error in closing file input.dat.\n");
    }

    if (fclose(foutp) == EOF)
    {
    printf("error in closing output.dat.\n");
    }
    return 0;
    } /*end of main */

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can combine those fprintf lines:

    fprintf( outputFile, "%u:%s", linenumber, buffer );

    Just a thought.

    Ok, so what's the problem? What do you need help with?
    Code:
    toList( buf, linenumber,
    	buf[0] == '_'	? UnderLineList :
    	isdigit(buf[0])	? NumberList :
    	isUpper(buf[0])	? UpperList :
    	isLower(buf[0])	? LowerList : NULL );
    See how easy that is?

    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM