我已經將Fprintf添加到SavePacket函數中,但它不能識別pos->目標,就像它使用outpackets函數一樣,如何添加代碼以便它將數據保存在我的鏈接中列表和FprintF它到我的文件?FprintF從linklist到文件
void outputPackets(node **head)
{
/*********************************************************
* Copy Node pointer so as not to overwrite the pHead *
* pointer *
**********************************************************/
node *pos = *head;
/*********************************************************
* Walk the list by following the next pointer *
**********************************************************/
while(pos != NULL) {
printf("Source: %i Destination: %i Type: %i Port: %i \n", pos->Source, pos->Destination, pos->Type, pos->Port, pos->next);
pos = pos->next ;
}
printf("End of List\n\n");
}
void push(node **head, node **aPacket)
{
/*********************************************************
* Add the cat to the head of the list (*aCat) allows the *
* dereferencing of the pointer to a pointer *
**********************************************************/
(*aPacket)->next = *head;
*head = *aPacket;
}
node *pop(node **head)
{
/*********************************************************
* Walk the link list to the last item keeping track of *
* the previous. when you get to the end move the end *
* and spit out the last Cat in the list *
**********************************************************/
node *curr = *head;
node *pos = NULL;
if (curr == NULL)
{
return NULL;
} else {
while (curr->next != NULL)
{
pos = curr;
curr = curr->next;
}
if (pos != NULL) // If there are more cats move the reference
{
pos->next = NULL;
} else { // No Cats left then set the header to NULL (Empty list)
*head = NULL;
}
}
return curr;
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** 保存Pakcet代碼功能 / ** * ** * ** * ** * ** * ** * * * * ** * ** * ** * ** * **所有的* ** *
void SavePacket(){
FILE *inFile ;
char inFileName[10] = { '\0' } ;
printf("Input file name : ") ;
scanf("%s", inFileName) ;
unsigned long fileLen;
//Open file
inFile = fopen(inFileName, "w+");
if (!inFile)
{
fprintf(stderr, "Unable to open file %s", &inFile);
exit(0);
}
fprintf("Source: %i Destination: %i Type: %i Port: %i \n", pos->Source, pos->Destination, pos->Type, pos->Port, pos->next);
}
好吧,我改變了代碼本, fprintf中INT((INFILE,爲const char * POS->源,POS->目標,pos-> Type,pos-> Port); 但我仍然收到一個錯誤,說'預期的聲明說明符或'......'之前)令牌' – user1949280 2013-05-03 13:35:22
@ user1949280要小心,你把兩個''一開始,你在中間留下了一個流浪的'const char *',不管怎樣,我完成了我的答案。 – Morwenn 2013-05-03 13:36:17
int fprintf(inFile,const char *; pos-> Source,pos-> Destination,pos-> Type,pos-> Port); 在const之前有一個錯誤sayin),但這會增加更多的問題? – user1949280 2013-05-03 13:38:56