5 Replies - 1088 Views - Last Post: 11 January 2008 - 12:33 AM Rate Topic: -----

#1 tommy_chai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-November 07

how to use data obtain in one C file in another C file?

Posted 30 December 2007 - 05:36 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: how to use data obtain in one C file in another C file?

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

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

Posted 30 December 2007 - 09:52 AM

not entirely sure I understand... but let me try.

If you want to be able to use the struct and functions from corners.c in the program try.c there are a few ways to do this.

#1 Create a header file 'corners.h' and include it in both corners.c and try.c, then you can compile the two files so that the linker gets both object files.

#2 You can simply include 'corners.c' into 'try.c'

Method #1 is the preferred way. (the second way creates tons of problems -- but sometimes it just the ticket).

What compiler are you using?
Was This Post Helpful? 0
  • +
  • -

#3 tommy_chai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-November 07

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

Posted 30 December 2007 - 08:31 PM

I am using Microsoft Visual Studio C++.
Yup, you are right, i am looking to reuse the data set obtained from Corners.c in try5.c
I am a very beginner in C. Hope you can show me more in codes connected to my attached program so I am able to understand.
Maybe i sound a little stupid but no doubt i am a dummy in C.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 tommy_chai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-November 07

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

Posted 06 January 2008 - 01:52 AM

Hi,
my problem is how to save the data/values into a header file before being called or reused in another C file?

Anyone please help. Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

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

Posted 06 January 2008 - 09:52 AM

You need to declare the variable as an extern variable in the header file.

An example...

stuff.h
#ifndef _STUFF_H_
#define _STUFF_H_

extern int number;

#endif


stuff.c
#include "stuff.h"

int number = 5;


main.c
#include <stdio.h>
#include <stdlib.h>
#include "stuff.h"

int main()
{
	printf("%d\n", number);

	return 0;
}



You can't define variables in header files. You can only say that they exist and leave them for someone else to define (same goes for functions).
Was This Post Helpful? 0
  • +
  • -

#6 tommy_chai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-November 07

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

Posted 11 January 2008 - 12:33 AM

Thanks for the example. I will try it out and hope it works for my case.

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1