c - FprintF from linklist to file -


i have added fprintf savepacket function doesn't recognise pos->destination withing outpackets function, how addapt code takes data saved in link-list , fprintf's file?

void outputpackets(node **head) {   /********************************************************* * copy node pointer not overwrite phead     * * pointer                                                * **********************************************************/ node *pos = *head;  /********************************************************* * walk list following 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 cat head of list (*acat) allows * * dereferencing of pointer pointer              * **********************************************************/ (*apacket)->next = *head; *head = *apacket; }  node *pop(node **head) { /********************************************************* * walk link list last item keeping track of   * * previous. when end move end     * * , spit out last cat in 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 more cats move reference     {         pos->next = null;     } else {         // no cats left set header null (empty list)         *head = null;     } } return curr; 

/*************************************** save pakcet code function /***************************************

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 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);    } 

first of all, should @ the function signatures of printf , fprintf. printf in outputpackets good. however, here fprintf signature:

int fprintf(file* stream, const char* format, ...); 

the first argument should file*. however, called function that:

fprintf("source: %i destination: %i type: %i port: %i \n", pos->source, pos->destination, pos->type, pos->port, pos->next); 

in call, first argument format string while should file*. that's why don't result expected.

moreover, in both calls printf , fprintf, last value give, pos->next, useless , can remove it.

edit: exact, line should have been

fprintf(infile, "source: %i destination: %i type: %i port: %i \n", pos->source, pos->destination, pos->type, pos->port); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -