Jump to content

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

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
tommy_chai

tommy_chai

    Newbie

  • Members
  • PipPip
  • 16 posts
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.


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
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
Basically you are talking about storing a value in one file for access in another?

The C Book — Linkage

That link talks about external linkage in C.

#3
tommy_chai

tommy_chai

    Newbie

  • Members
  • PipPip
  • 16 posts
Thanks. I will try to learn and understand. It takes time for a beginner like me.

#4
yulin11

yulin11

    Newbie

  • Members
  • Pip
  • 7 posts
could you speak it clearer?i can't understand!

#5
tommy_chai

tommy_chai

    Newbie

  • Members
  • PipPip
  • 16 posts
Sorry. Actually, what I want to do is to reuse the data values in struct coordinate in a new file named try5.c

I have tried to achieve that by create a header file, manually insert the data, and called header file in try5.c

Now, my problem is in Corners.c. How can I save those data values in struct into a header file by using programming? So that I don't need to type them manually. Please help. Thanks.

#6
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
Do you mean you want to reuse the struct or a particular instance of that struct. To reuse the struct then put it in a header Corners.h then import that header into Corners.c and any other file you want to reuse it.

#7
tommy_chai

tommy_chai

    Newbie

  • Members
  • PipPip
  • 16 posts
Yes I want to reuse the value in the struct. In this case, it's values for x and y. Yea, but how to write it? Do you mind to show me in codes? It's quite hard for a beginner like me to understand it. My problem as stated is how to save those values in struct into header files automatically?
This is because now I manually type all the values into the header files and called them in another new C file,'try5.c' for reuse purpose.

#8
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts

Corners.h

struct Coordinate

{

	int x;

	int y;

};


-------------------------------------------------------


Corners.c


import "Corners.h"


susan_corners(in,r,bp,max_no,corner_list,x_size,y_size){

:

:

struct Coordinate left_corner, right_corner;

}


try5.c

:

:

import "Corners.h"

#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]);

:

:

}



#9
tommy_chai

tommy_chai

    Newbie

  • Members
  • PipPip
  • 16 posts
Okay, I got you. First save the struct Coordinate{} in Corners.h
Then, import the header files into both programs. That means I need to delete the declaration of struct Coordinate{} in Corners.c?

Thank you for your solution.

#10
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
Yeah that's it. Anything you want to share between files (usually struct or function definitions) goes in a header file.