Click here to Skip to main content
15,892,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi guys,

I have a problem the my program works in one file and does not work in between files. Can some one throw some light on it.
C
ifd= open("server.cfg",O_RDONLY);
    while((retin = read(ifd,&str,650)) > 0 )
  {
      //i=1;
        printf("String is = %s",str);
        pch = strtok (str," \n");
        while (pch != NULL)
        {
            printf ("IN:%s\n",pch);
            pch = strtok(NULL," =\n");
            if ( pch[0] == 'E') break;

            printf("pch =%s",pch);
            if ( pch[0] != '[')
                add_to_list(pch,true);
            //printf("Key is:=%s",pch);

        }   

    }

    close(ifd);
    struct data_struct *head = NULL;
    struct data_struct *ptr = head;


    ptr = search_in_list("clientip", NULL);
    if ( ptr != NULL)
    {
        printf("\nClientIp:%s\n",ptr->val);
        ip =  ptr->val;
    }
    else
    {
        printf("Can't Find ClientIp to connect\n");
        //exit(0);
    }



Above code works when put in same file.

But when I put above code of adding in link list in file and searching in other file this does not work and search list function fails to return any values.


Any idea why so ??????


I have 2 files : server.c and comfunc.c

when i put my whole code in any single file it works fine but when i divide my code in say
addlist in comfunc.c and
searchlist in server.c

it does not work.
values from searchlist are not returned properly. it returns NULL pointer.

but when in same file search completes fine and returns the searched value.
Posted
Updated 9-Jul-15 23:24pm
v3
Comments
Andreas Gieriet 10-Jul-15 2:46am    
I did set the code into a preformatted block.
Andi
Richard MacCutchan 10-Jul-15 4:32am    
What do you mean by "does not work in between files"
Please explain exactly what the problem is, and show where in the code the error occurs. We cannot read your mind.
Andreas Gieriet 10-Jul-15 15:36pm    
Please remove your "Solution" - it is *not* a solution!
Use the "Improve question" link above (move your mouse to the far right of your name below you question) to edit your question.
Andi

1 solution

I have 2 files : server.c and comfunc.c

when i put my whole code in any single file it works fine but when i divide my code in say
addlist in comfunc.c and
searchlist in server.c

it does not work.
values from searchlist are not returned properly. it returns NULL pointer.

but when in same file search completes fine and returns the searched value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900