I have a program that has an array of pointers such as:
INTLIST* myArray[countOfRows];
each myArray
pointer points to a linked list, basically it becomes an M*N matrix.
So for example:
3 2 1
2 1 0
1 9 8
So myArray[0]
is a linked list with 3->2->1
and myArray[1]
is a linked list with 2->1->0..
and so on. I have a function that prints the matrix which basically does this:
for(int i = 0; i<countOfRows; i++)
list_print(myArray[i]);
And then my list_print function is like so:
void list_print(INTLIST* list)
{ /* This function simply prints the linked list out */
INTLIST* temp=NULL; //temp pointer to head of list
/* loops through each node of list printing its datum value */
for(temp=list; temp!=NULL; temp=temp->next)
{
printf("%d ", temp->datum); //print datum value
}
printf("\n");
}
This is all great and working fine, (I know i could optimize and clean up and I promise to do so). Now my next question is I need to write this matrix out to a text file. So I tried this:
char* outputFileName = "out.txt";
FILE* ofp;
ofp=fopen(outputFileName, "w");
if(ofp == NULL)
{
printf("Cannot open writeable file!");
return -1;
}
for(i=0; i<fileLineCount; i++)
{
fprintf(ofp, list_print(aList[i]);
}
But I take it its not that simple. Can anyone show me how to print this out to a text file...
Thanks