Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Unable to assign the runtime values to variables in a sub function

Hi,

[C] [Linux(UBUNTU)] [gcc]

Desired functionality:

We are trying to store the objects, related pixels and x,y coordinates of pixels into a file. However, if the objectcount (oc) has pixel value(pc) less than 5, it should not print the object. If the number of pixels is greater than 5 then object should be printed into a file. For every Object value of pc starts from 1 and extends till maximum value of pc.

The code given below does the process of printing all the objects, pixels related to that object and corresponding x,y coordinates of those pixels. that are identified in an image.

Our Approach :

We have tried to store the pixel values from 1 to 4 and retrieve those values when the pixel count is more than 5. The pixel's coordinates are not being stored into the file. Even after variables are initialized, the runtime values x,y are not being stored into the assigned variables.

[Code]

void addToObject(long x, long y, long pc, int oc)
{
FILE *fp;
char *c;
long n1,n2,n3,n4,n5,n6,n7,n8;
fp=fopen("negpxls.txt","a+");
n1=n2=n3=n4=n5=n6=n7=n8=0;
if (pc <= 1) // {fprintf(fp,"
Object %d :
",oc);}
{
//fprintf(fp,"n x= %ld y= %ld
", x,y);
n1=x;
n2=y;
}
if (pc<=2)
{
n3=x; n4=y;
}
if (pc<=3)
{
n5=x; n6=y;
}
if (pc<=4)
{
n7=x; n8=y;
}
if (pc==5)
{

fprintf(fp,"
Object : %d
",oc);
fprintf(fp,"
Pixel : %ld (%ld,%ld)
", pc-4,n1,n2);
fprintf(fp,"
Pixel : %ld (%ld,%ld)
", pc-3,n3,n4);
fprintf(fp,"
Pixel : %ld (%ld,%ld)
", pc-2,n5,n6);
fprintf(fp,"
Pixel : %ld (%ld,%ld)
", pc-1,n7,n8);
fprintf(fp,"
Pixel : %ld (%ld,%ld)
", pc, x,y);
}
if(pc>=6)
fprintf(fp,"
Pixel : %ld (%ld,%ld)
", pc, x,y);
printf("
Object %d :
",oc);
printf("
Pixel %ld : (%ld,%ld)
", pc, x,y);
fclose(fp);
}

[/Code]

Thanks

Sign In or Register to comment.