Hi,

I posted previously that I was trying to import C code that I previously wrote into a C# utility that I recently wrote. I was advised to create a dll, but after some research, I realized it was way too difficult for me. Since my code is realitively short, I decided to attempt to convert syntax to C#. Here is where I am having difficulty.

My C code contained these structs:
Code:
typedef struct{						/* This struct defines the sub-units of time */
	char sec[10];
	char nsec[15];
	char msec[15];
} timeType;

typedef struct{						/* This struct defines the fields in each line of raw data */
	char count[4];
	timeType time;					/* time for the event */
	char desc[21];					/* something descriptive about this event */
	char val[11];
} eventType;

typedef struct{						/* This struct will hold the path of an event */
	char dest1 [20];				/* each member of the struct represents a filename */
	char dest2 [20];				/*		in the path of the form: _____________.csv */
	char dest3 [20];
	char dest4 [20];
	char dest5 [20];
	char dest6 [20];
} mapType;
I would create pointers to pointers of the mapType struct:

Code:
   mapType onePath[1];				/* One instance of the map type to hold path for current operation */
   mapType *pathPtr = onePath;

   eventType **ptrArray1;			/* Pointers to dynamic arrays of pointers: each will hold a pointer to an event struct */
   eventType **ptrArray2;
   eventType **ptrArray3;
   eventType **ptrArray4;
   eventType **ptrArray5;
   eventType **ptrArray6;
Finally, I would allocate space to fill each array with raw data from a csv file. The ptrArrays are sent to a dump function where each is written out to a file:
( the dest. is created in another function. It is an array of filenames (.csv) )
Code:
/*
			The number of lines will be calculated for each file in the path.
			A dynamic array for structs will be allocated for each file and then
			filled with the raw data of the file using the function CsvParse.  Finally,
			the space used for the dynamic array will be freed.  
			*/

			//calloc(numberoflines+2...) so that the last set of the array of pointers
			//are always NULL.  calloc will initialize all to 0 (NULL).  This will be useful
			//when testing when we've moved beyond the scope of valid data in the array.
			mfcCount = CountLines(inputFilename);
			ptrArray1 = calloc(mfcCount+2, sizeof(eventType *));
			CsvParse(inputFilename, ptrArray1);

			numOfLines = CountLines( pathPtr->dest2 );
			ptrArray2 = calloc(numOfLines+2, sizeof(eventType *));
			CsvParse(pathPtr->dest2, ptrArray2);

			numOfLines = CountLines( pathPtr->dest3 );
			ptrArray3 = calloc(numOfLines+2, sizeof(eventType *));
			CsvParse(pathPtr->dest3, ptrArray3);

			numOfLines = CountLines( pathPtr->dest4 );
			ptrArray4 = calloc(numOfLines+2, sizeof(eventType *));
			CsvParse(pathPtr->dest4, ptrArray4);

			numOfLines = CountLines( pathPtr->dest5 );
			ptrArray5 = calloc(numOfLines+2, sizeof(eventType *));
			CsvParse(pathPtr->dest5, ptrArray5);

			numOfLines = CountLines( pathPtr->dest6 );
			ptrArray6 = calloc(numOfLines+2, sizeof(eventType *));
			CsvParse(pathPtr->dest6, ptrArray6);
			
			sprintf(summaryFilename, "RawSummary_mfcDevice%d.csv", mfcOutputFileNumber);
			mfcOutputFileNumber++;

			DumpTimeline_mfc(summaryFilename, mfcCount, ptrArray1, ptrArray2, ptrArray3,
													ptrArray4, ptrArray5, ptrArray6);
			free(ptrArray1);
			free(ptrArray2);
			free(ptrArray3);
			free(ptrArray4);
			free(ptrArray5);
			free(ptrArray6);
Now, my problem is that I want the number of ptrArrays to be data driven. I am thinking that if I read an external file that has the sequence of the files, I will know how many ptrArrays to allocate. How can I use the ArrayList in C# to perform this? I want to be able to store raw data in eventType structs into a data-driven number of ArrayList elements (appologies for my wording, I'm new to programming) and eventually dump them to an external file.

My program will have a database of many raw .csv files. It will access certain ones based on a sequence (in the form of filenames) given in an external file. It will search the first file for a start timestamp, then the next for a corresponding timestamp, and so on. Each completed timeline will be dumped to an external summary file.

So far, on the C# side I have a function that opens and external file and creates the filenames path:
Code:
public void FillTemplates(string inputFilename, ArrayList fileTemplates_MFC, ArrayList fileTemplates_SW)
        {
            string theSourcePath;
            
            //Create Path
            theSourcePath = "C:\\Documents and Settings\\Mobile2\\Desktop\\PROJECT SOURCE FILES\\";
            theSourcePath = String.Concat(theSourcePath, inputfilename);

            using (CSVReader csv = new CSVReader(@theSourcePath))
            {
                string[] fields;

                //MFC templates
                fields = csv.GetCSVLine();
                foreach (string field in fields)
                {
                    fileTemplates_MFC.Add(field);
                }

                //SW templates
                fields = csv.GetCSVLine();
                foreach (string field in fields)
                {
                    fileTemplates_SW.Add(field);
                }

            }

        }

 public void FilePath(string pathStart, ArrayList pathArray, ArrayList fileTemplates)
        {

	        int  found = 0;						        /* Flag to indicate path found */
            int i = 0;
            string filename = "paths.csv";				/* name of file that contains filemap */
            string theSourcePath;
            string[] fields;
            string tempString;

            //Create Path
            theSourcePath = "C:\\Documents and Settings\\Mobile2\\Desktop\\PROJECT SOURCE FILES\\";
            theSourcePath = String.Concat(theSourcePath, filename);

            using (CSVReader csv = new CSVReader(@theSourcePath)) /* read each line in file until correct one found */
            {
                while((fields = csv.GetCSVLine()) != null)
                {
                    if (pathStart.CompareTo(fields[0]) == 0)      /* compare */
                    {
                        found = 1;
                        break;                                    /* break out of loop when found */
                    }
                }
            }
            

	        /* if found, parse the line that contains correct path */
	        if ( found )
	        {
                foreach (string field in fields)
                {
                    tempString = fileTemplates[i];
                    tempString = String.Concat(field);
                    tempString = String.Concat(".csv");
                    pathArray.Add(tempString);
                    i++;
                }
	        }
	        else
	        { Console.WriteLine ("Start of path {0} not found.  Please define path in paths.csv\n", pathStart); }
        		
        }

Thank You for your time. Please let me know if you need further explaination of what I am trying to accomplish.