我已经将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