We are going to be given a .csv file in which we don't know how many lines it contains. In that .csv, each line consists of 6 float-type integers numbers that we have to store in one node of the linked list. But seeing as how the .csv we'll be given contains an unknown amount of lines, we also wouldn't know how long our linked list should last.
OK so clearly I can't figure some stuff out. What I did previously was to create an n-number of temporary nodes (but I knew what n was back then), link them all together, then make the actual list be equal to the first temporary node. But now that I don't know how many lines I'll be facing, I can't just declare a million temporary nodes for that...
I've tried stuff out but this didn't seem to work:
But stuff errors at the pCurrent->pNext=CreateNewNode(data); line , because that is currently nothing. I can't also pCurrent=pCurrent->pNext; yet because as the same, pCurrent->pNext doesn't even exist yet. How can I do it such that, an empty node gets created in the loop? I was actually trying to make an array of nodes with a blank number of members, but apparently that isn't valid ._.
(btw here are the codes we use for nodes)
EDIT: I also had the idea of first counting the number of lines in the .csv (with the fetchNextData() function), then I'll malloc that number into the list (like pUnlabelled = malloc(sizeof(nodeStructType)*x);) , though I don't know if that'll work...
OK so clearly I can't figure some stuff out. What I did previously was to create an n-number of temporary nodes (but I knew what n was back then), link them all together, then make the actual list be equal to the first temporary node. But now that I don't know how many lines I'll be facing, I can't just declare a million temporary nodes for that...
I've tried stuff out but this didn't seem to work:
loadSpeechData(unlabelled);
do
{
data.pitchMin = getPitchMin();
data.pitchMax = getPitchMax();
data.pitchAve = getPitchAve();
data.energyMin= getEnergyMin();
data.energyMax= getEnergyMax();
data.energyAve= getEnergyAve();
strcpy(data.emotion,getEmotion());
pTemp=CreateNewNode(data);
if(pUnlabelled==NULL)
{
pUnlabelled=pTemp;
pCurrent=pUnlabelled;
}
else
{
//printf("%d", pUnlabelled->pNext);
pCurrent->pNext=CreateNewNode(data);}
pCurrent=pCurrent->pNext;
free(pTemp);
x++; i++;
}while(fetchNextData()+1);
But stuff errors at the pCurrent->pNext=CreateNewNode(data); line , because that is currently nothing. I can't also pCurrent=pCurrent->pNext; yet because as the same, pCurrent->pNext doesn't even exist yet. How can I do it such that, an empty node gets created in the loop? I was actually trying to make an array of nodes with a blank number of members, but apparently that isn't valid ._.
(btw here are the codes we use for nodes)
SPOILER
//-------------------Node Codes Here
/*
nodetype.h
*/
struct dataTag {
float pitchMin;
float pitchMax;
float pitchAve;
float energyMin;
float energyMax;
float energyAve;
char emotion[99];
};
struct nodeTag {
struct dataTag data;
struct nodeTag *pNext;
};
typedef struct dataTag dataStructType;
typedef struct nodeTag nodeStructType;
//-----End of nodetype.h
nodeStructType *InitializeList(void)
{
return NULL;
}
nodeStructType *CreateNewNode(dataStructType data)
{nodeStructType *pTemp;
if (( pTemp = malloc ( sizeof ( nodeStructType))) == NULL){
printf (" ERROR: not enough memory .\n");
exit (1);
}
/* initialize node members */
pTemp ->data = data;
pTemp ->pNext = NULL;
return pTemp ;
}
EDIT: I also had the idea of first counting the number of lines in the .csv (with the fetchNextData() function), then I'll malloc that number into the list (like pUnlabelled = malloc(sizeof(nodeStructType)*x);) , though I don't know if that'll work...