I am a high school student doing a summer project in AI.
I am not experienced enough with linked lists and I need your help to put some values into linked list.

I would like to make 4 linked lists (superarrays). Can I use this one function below for all 4 linked lists?
What is the headRef variable for? Does it contain the name of the linked list?

Please help me build a linked list that would seek 2nd, 3rd, 4th, and 42nd field in the following line and append each new value within that field to this field's linked list. Fields are groups of values that are between commas.
// I decided to use linked lists rather than arrays because in the array you have to know the length of the array, but I do not know how many values each field has.
Also, I am working in the linux environment and use g++ compiler (both C and C++)... but I doubt that this compiler is any different from the Turbo C++ compiler
--------------------------------------------------------------------------------------------------------
For example:
the lines are:
0,tcp,http,SF,241,259,0,0,1,0,0,etc...,0,normal.
0,tcp,smtp,SF,432,543,0,0,1,0,0,etc...,0,normal.
0,udp,ftp,SF,511,777,0,1,1,0,0,etc...,0,normal.
(the actual dataset is much longer and consists of 43 fields)
The program should put the values of second field (tcp,udp,etc...) into the linked list #2 (because the source file is huge and I dont know how many values each field has), and values of field 3 (http, smtp, ftp, etc...) into a separate linked list #3. Provided that the code for extracting these fields is known and each field is stored in char buff[50] (I am not asking you to create a whole program), can you please help me put nonnumerical fields into linked list that after going through all source file would assign different values within the same field different numbers. If for example, for field 3 http was the first value added to liked list #3, it would be assigned 1, smtp would be assigned 2, and ftp would be assigned 3, and so on depending on the order these values were extracted from the source file.
Below is the function that would append new fields to the linked list. And below that, there is a complete code of the program that extracts nonnumerical fields from the source file.

==================================================
======================
Function for appending new values to the linked lists.
--------------------------------------------------------------------------------------------------------------
Code:
struct node* AppendNode(struct node** headRef, char var[50]) {
    struct node* current = *headRef;
    struct node* newNode;
    newNode = malloc(sizeof(struct node));
    newNode->data = var;
    newNode->next = NULL;
// special case for length 0
    if (current == NULL) {
        *headRef = newNode;
    }
    else {
// Locate the last node
        while (current->next != NULL) {
            current = current->next;
        }
        current->next = newNode;
    }
}
==================================================
============
The actual code of field seeking program
-------------------------------------------------------
Code:
#include <string.h>
#include<iostream.h>
#include<fstream.h> 
#include<ctype.h>
int main() 
{ 
    const long BUFF_SIZE = 1000000;
    int a, b, c;
    ifstream infile;
    ofstream outfile;
    char buff[BUFF_SIZE];
    char outbuff[BUFF_SIZE];
    char output[50][50]; // using an array of char arrays.
// open the files
    infile.open("data.txt");
    outfile.open("output.txt");
// make sure the files are open
    if(!infile.is_open()){
        cerr << "error opening input file";
        return 1;
    }
    if(!outfile.is_open()){
        cerr << "error opening output file";
        return 1;
    }
// loop until the end of the input file
    for(a=0; !infile.eof(){
// read in one line
        infile.get(buff, BUFF_SIZE, '.');
        infile.ignore(1);
// loop through each char in the current line
        for(b=c=0; buff[b]; ++b){
// eat whitespace
            while(buff[b] == ' ')
                ++b;
// ignore numbers and commas in the input
// copy everything else to the output buffer.
            if(!isdigit(buff[b]) && buff[b] != ','){
                outbuff[c++] = buff[b];
            }
// when we come to a comma or the end of the input buffer
// AND there is something in the output buffer,
// move contents of output buffer to the next array in the output 2D array.
// print the output to the screen and the output file
            if((buff[b] == ',' !buff[b+1]) && strlen(outbuff) > 0){
                outbuff[c] = '\0'; 
                strcpy(output[a], outbuff);
                cout << output[a] << endl;
                outfile << output[a] << endl;
// increment the end output array counter
                ++a;
// start the output buffer counter again
                c = 0;
// reset the output buffer
                outbuff[0] = '\0';
            }
        }
    }
// close the files
    infile.close();
    outfile.close();
// pause so you can see the output on the screen
    cout << " **** All done! ****\n";
    cin.get();
    return 0;
}
--------------------------------------------------------------------------------

-----------------------------------------
Thanks alot! =),



__________________
Dmitry Kashlev