CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2007
    Posts
    27

    How to use the data obtain in one C file to another C file?

    Hi guys,
    First, I detect coordinates for left and right corners of a mouth in Corners.c and saved in struct Coordinate for 72 images.
    How can I able to link it to another C file, let's say try5.c so that it can be used for template matching purpose when i execute 72 images in a loop in try5.c?
    Sorry because I cannot provide the full program because it is a way too long to read. These are the parts which i think very important in order to solve the problem. Help from anyone will be appreciated.

    Thank you very much.

    Code:
    Corners.c
    struct Coordinate
    {
    	int x;
    	int y;
    };
    susan_corners(in,r,bp,max_no,corner_list,x_size,y_size){
    :
    :
    struct Coordinate left_corner, right_corner;
    }
    
    try5.c
    :
    :
    #define NUM 72
    :
    main()
    {
    :
    :
    if((fp33 = fopen("facecolor_input.dat","r")) == NULL){
    		printf("File input filename2  can not open\n");
    		exit(1);
    	}
    	for(k=0;k<NUM;k++){
    		fscanf(fp33,"%s",filename33[k]);
    	}
    	fclose(fp33);
    :
    :
    for(total = 0; total<NUM; total ++){    
    	
    		printf("\nimage==>%d\n",(total+1));
    
    /** read the color data from the file of input face image **/
    		read_data_color(filename33[total],inpcolor);
    :
    :
    /*     Template Matching   */
    //example for eye template matching
                    XX1=56;   // Left X coordinate for eye template
    	YY1=44;
    	XX2=164; //right X coordinate for eye template
    	YY2=44;
    // plf_x, plf_y, prg_x, prg_y are the left and right x & y coordinates from the full input image which has been obtained in Corners.c
    	affine_recog_a(plf_x, plf_y, prg_x, prg_y, XX1, YY1, XX2, YY2);
    	cross_correlation_recog_a(TEMPLATE_a, image_out_a, &CC1[0]);
    :
    :
    }
    Best regards,
    Tommy

  2. #2
    Join Date
    Aug 2004
    Location
    Bucharest, Romania... sometimes
    Posts
    1,039

    Re: How to use the data obtain in one C file to another C file?

    Have the struct declared in a header file (*.h) included in both translation units (*.c), and then pass a pointer to the data as parameter when calling the appropriate function. To use a function from one translation unit in another, make a function prototype declaration available in the same header file which is included in both translation units.
    Hope the answer is clear and helps you solve your issue.
    Regards,
    Bogdan Apostol
    ESRI Developer Network

    Compilers demystified - Function pointers in Visual Basic 6.0
    Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.

    Customize your R2H
    The unofficial board dedicated to ASUS R2H UMPC owners.

  3. #3
    Join Date
    Nov 2007
    Posts
    27

    Re: How to use the data obtain in one C file to another C file?

    Thank you very very much for the reply. Do you mind to make it in programming codes which can be connected with my attached codes?
    I have to admit that though i can get what you mean but i have no idea how to write it because i am just a dummy in C, beginner. Do you mind to further educate me on your idea? Please help.
    Thank you very much.

    Best regards,
    Tommy

  4. #4
    Join Date
    Nov 2007
    Posts
    27

    Re: How to use the data obtain in one C file to another C file?

    Anyone can help?

  5. #5
    Join Date
    Nov 2007
    Posts
    27

    Re: How to use the data obtain in one C file to another C file?

    Anyone, please help!

  6. #6
    Join Date
    Jan 2008
    Location
    Bangalore, India
    Posts
    2

    Re: How to use the data obtain in one C file to another C file?

    hi tommy

    as bornish said that u take one function in ur header file ex. fun1(struct*)
    declare its prototype in ur header file.

    now calling fun1(...) in both the c files u can achieve ur target.

    I'd like to ask Bornish that can we do it wth creating function pointer so that
    at any time during execution we can use data generated by function in one file to another?????

    I think we can do it but not 100% sure, if u can comment on my idea then it ll be helpful for me.

  7. #7
    Join Date
    Aug 2004
    Location
    Bucharest, Romania... sometimes
    Posts
    1,039

    Re: How to use the data obtain in one C file to another C file?

    @tommy_chai:
    I hope you understand that I don't have time to re-write your code; I can only reply to specific questions and hope to give you enough hints on where to look in the documentation for finding complete explainations and code samples.
    @yogpal:
    I'm not sure I understood what you want to achieve, but I'll split my answer into a couple of explainations:
    1. Function pointers are used when the developer needs to call function(s) of which address may change during runtime. A few examples would be:
    - funtion(s) residing in external modules loaded at runtime (DLLs), for which the address is obtained with GetProcAddress() API
    - when a module needs to register a callback in order to receive events from other modules loaded in the same process space (including OS's DLLs)
    - using Strategy Patern, some implementations may need to dynamically change behaviour by calling different functions having same prototype; NOTE that same can be achieved through Polymorphism in OOP,... not always recommended (by me) though
    These where the first 3 that came through my mind, but there are plenty other situations when function pointers can be useful.
    2. To pass & return data between functions, in different translation units or NOT, does not require the use of function pointers, but parameters declared by reference, meaning either pointer or reference to the type of data needed to be [in,out]; please use with caution such parameters, in the sense of validating pointers before use and avoiding memory leaks by allocating / deallocating memory for the data in the caller, since error handling mechanisms have a tricky way to behave and may be a too advance concept for you to understand. As a beginner (not saying you are one), I would avoid using pointers... and instead, I would pass parameters through reference: void f(int & param);

    Best of luck to both of you!
    Cheers,
    Bogdan Apostol
    ESRI Developer Network

    Compilers demystified - Function pointers in Visual Basic 6.0
    Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.

    Customize your R2H
    The unofficial board dedicated to ASUS R2H UMPC owners.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured