V
Victor
I'm trying to run this java program, but somehow the program always
quit w/o giving any error msg at all. it happenned inside the first
case statements. Strangely, after printing happen2, it just stopped,
and I had no idea what happens.
another error is on the last function. I have already declared plane
as M x N array, but it keeps giving error like
hwone.cpp(50) : warning C4101: 'plane' : unreferenced local variable
hwone.cpp(212) : error C2065: 'plane' : undeclared identifier
hwone.cpp(212) : error C2109: subscript requires array or pointer type
hwone.cpp(212) : error C2109: subscript requires array or pointer type
hwone.cpp(212) : error C2106: '=' : left operand must be l-value
Error executing cl.exe.
hwone.exe - 4 error(s), 1 warning(s)
anybody can help me is really appreciated.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAXVERTICES (20) /*Maximum number of object's vertices*/
#define MAXFILENAME (20) /*Maximum characters of file's name*/
#define MAXDATA (40) //Maximum data can be read
#define M (256)
#define N (256)
struct vector {
double x;
double y;
double z;
}ic,jc,kc,O,C, posW[MAXVERTICES], camera_origin, temp, posC, pixel,
temp2;
struct cv {
int pos1;
int pos2;
}connected[20];
void solveK(struct vector one, struct vector two);
void solveI(struct vector one);
void solveJ();
void calcPc(int h);
void calcPixel(struct vector pos, int f, int no);
void calcOc(struct vector camera_origin, struct vector cam_origin,
struct vector one, int f);
void main(void)
{
FILE *fp;
char str[MAXFILENAME], record[MAXDATA];
char tempStr[5] = " ";
char emptyStr[MAXDATA];
int temp[MAXDATA];
int plane[M][N];
int ref[20];
int counter = 0;
int count = 0;
int acount = 0;
int focal = 0;
int edges = 0;
int vertices = 0;
int a = 0;
printf("Please Enter the data file name!\n");
printf("Name : ");
gets(str);
/*Checking file*/
if ((fp = fopen(str, "r")) == NULL)
{
printf("Cannot open file.\n");
exit(1);
}
while ( fgets( record, MAXDATA, fp ) != NULL )
{
strcat(record, tempStr);
printf("record is %s\n", record);
printf("tempStr is %s\n", tempStr);
int j = strlen(record);
printf("j is %d, and record a is %c\n",j,record[16]);
for ( int i = 0, k = 0 ; i < j ; i++ )
{
if ((record == ' ')&&(record[i+1] != ' '))
{
ref[k] = i;
printf("happen1 %d\n", ref[k]); //testing
k++;
}
emptyStr = ' ';
}
switch ( counter ) {
case 0:
{
printf("happen2\n"); <<--- quit around here
for ( a = 0 ; a < j ; a = a+1 )
{
temp[a] = atoi(record);
strncpy(record, emptyStr, ref[a]);
}
O.x = temp[0];
O.y = temp[1];
O.z = temp[2];
C.x = temp[3];
C.y = temp[4];
C.z = temp[5];
focal = temp[6];
counter++;
break;
}
case 1:
{
printf("happen3\n");
for ( int b = 0 ; b < j ; b++ )
{
temp = atoi(record);
strncpy(record, emptyStr, ref);
}
edges = temp[0];
vertices = temp[1];
counter++;
break;
}
case 2:
{
printf("happen3\n");
for ( int c = 0 ; c < j ; c++ )
{
temp[c] = atoi(record);
strncpy(record, emptyStr, ref[c]);
}
posW[count].x = temp[0];
posW[count].y = temp[1];
posW[count].z = temp[3];
if (count == vertices)
counter++;
count++;
break;
}
case 3:
{
printf("happen4\n");
for ( int d = 0 ; d < j ; d++ )
{
temp[d] = atoi(record);
strncpy(record, emptyStr, ref[d]);
}
connected[acount].pos1 = temp[0];
connected[acount].pos2 = temp[1];
if (acount == edges)
counter++;
acount++;
break;
}
}
}
printf("Oc is %f,%f,%f\n",O.x,O.y,O.z);
}
void solveK(struct vector one, struct vector two)
{
double a, b, c;
double temp;
a = two.x - one.x;
b = two.y - one.y;
c = two.z - one.z;
temp = sqrt(pow(a,2)+pow(b,2)+pow(c,2));
kc.x = (a/temp);
kc.y = (b/temp);
kc.z = (c/temp);
}
void solveI(struct vector one)
{
ic.x = sqrt(pow(one.y,2)/(pow(one.x,2)+pow(one.y,2)));
ic.y = sqrt(1 - pow(ic.x,2));
ic.z = 0;
}
void solveJ()
{
jc.x = ((kc.y*ic.z) - (kc.z*ic.y));
jc.y = ((kc.z*ic.x) - (kc.x*ic.z));
jc.z = ((kc.x*ic.y) - (kc.y*ic.x));
}
void calcOc(struct vector cam_origin, struct vector one, int f)
{
camera_origin.x = cam_origin.x + (one.x*f);
camera_origin.y = cam_origin.y + (one.y*f);
camera_origin.z = cam_origin.z + (one.z*f);
}
void calcPc(int h)
{
temp.x = posW[h].x - camera_origin.x;
temp.y = posW[h].y - camera_origin.y;
temp.z = posW[h].z - camera_origin.z;
posC.x = (ic.x*temp.x)+(ic.y*temp.y)+(ic.z*temp.z);
posC.y = (jc.x*temp.x)+(jc.y*temp.y)+(jc.z*temp.z);
posC.z = (kc.x*temp.x)+(kc.y*temp.y)+(kc.z*temp.z);
}
/*
void calcPixel(struct vector pos, int f, int no)
{
temp2.x = (f/pos.z)*pos.x;
temp2.y = (f/pos.z)*pos.y;
pixel.x = temp2.x + (M-1)/2;
pixel.y = (N-1)/2 - temp2.y;
int tempo1 = (int) pixel.x;
int tempo2 = (int) pixel.y;
plane[tempo1][tempo2] = no;
}*/
quit w/o giving any error msg at all. it happenned inside the first
case statements. Strangely, after printing happen2, it just stopped,
and I had no idea what happens.
another error is on the last function. I have already declared plane
as M x N array, but it keeps giving error like
hwone.cpp(50) : warning C4101: 'plane' : unreferenced local variable
hwone.cpp(212) : error C2065: 'plane' : undeclared identifier
hwone.cpp(212) : error C2109: subscript requires array or pointer type
hwone.cpp(212) : error C2109: subscript requires array or pointer type
hwone.cpp(212) : error C2106: '=' : left operand must be l-value
Error executing cl.exe.
hwone.exe - 4 error(s), 1 warning(s)
anybody can help me is really appreciated.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAXVERTICES (20) /*Maximum number of object's vertices*/
#define MAXFILENAME (20) /*Maximum characters of file's name*/
#define MAXDATA (40) //Maximum data can be read
#define M (256)
#define N (256)
struct vector {
double x;
double y;
double z;
}ic,jc,kc,O,C, posW[MAXVERTICES], camera_origin, temp, posC, pixel,
temp2;
struct cv {
int pos1;
int pos2;
}connected[20];
void solveK(struct vector one, struct vector two);
void solveI(struct vector one);
void solveJ();
void calcPc(int h);
void calcPixel(struct vector pos, int f, int no);
void calcOc(struct vector camera_origin, struct vector cam_origin,
struct vector one, int f);
void main(void)
{
FILE *fp;
char str[MAXFILENAME], record[MAXDATA];
char tempStr[5] = " ";
char emptyStr[MAXDATA];
int temp[MAXDATA];
int plane[M][N];
int ref[20];
int counter = 0;
int count = 0;
int acount = 0;
int focal = 0;
int edges = 0;
int vertices = 0;
int a = 0;
printf("Please Enter the data file name!\n");
printf("Name : ");
gets(str);
/*Checking file*/
if ((fp = fopen(str, "r")) == NULL)
{
printf("Cannot open file.\n");
exit(1);
}
while ( fgets( record, MAXDATA, fp ) != NULL )
{
strcat(record, tempStr);
printf("record is %s\n", record);
printf("tempStr is %s\n", tempStr);
int j = strlen(record);
printf("j is %d, and record a is %c\n",j,record[16]);
for ( int i = 0, k = 0 ; i < j ; i++ )
{
if ((record == ' ')&&(record[i+1] != ' '))
{
ref[k] = i;
printf("happen1 %d\n", ref[k]); //testing
k++;
}
emptyStr = ' ';
}
switch ( counter ) {
case 0:
{
printf("happen2\n"); <<--- quit around here
for ( a = 0 ; a < j ; a = a+1 )
{
temp[a] = atoi(record);
strncpy(record, emptyStr, ref[a]);
}
O.x = temp[0];
O.y = temp[1];
O.z = temp[2];
C.x = temp[3];
C.y = temp[4];
C.z = temp[5];
focal = temp[6];
counter++;
break;
}
case 1:
{
printf("happen3\n");
for ( int b = 0 ; b < j ; b++ )
{
temp = atoi(record);
strncpy(record, emptyStr, ref);
}
edges = temp[0];
vertices = temp[1];
counter++;
break;
}
case 2:
{
printf("happen3\n");
for ( int c = 0 ; c < j ; c++ )
{
temp[c] = atoi(record);
strncpy(record, emptyStr, ref[c]);
}
posW[count].x = temp[0];
posW[count].y = temp[1];
posW[count].z = temp[3];
if (count == vertices)
counter++;
count++;
break;
}
case 3:
{
printf("happen4\n");
for ( int d = 0 ; d < j ; d++ )
{
temp[d] = atoi(record);
strncpy(record, emptyStr, ref[d]);
}
connected[acount].pos1 = temp[0];
connected[acount].pos2 = temp[1];
if (acount == edges)
counter++;
acount++;
break;
}
}
}
printf("Oc is %f,%f,%f\n",O.x,O.y,O.z);
}
void solveK(struct vector one, struct vector two)
{
double a, b, c;
double temp;
a = two.x - one.x;
b = two.y - one.y;
c = two.z - one.z;
temp = sqrt(pow(a,2)+pow(b,2)+pow(c,2));
kc.x = (a/temp);
kc.y = (b/temp);
kc.z = (c/temp);
}
void solveI(struct vector one)
{
ic.x = sqrt(pow(one.y,2)/(pow(one.x,2)+pow(one.y,2)));
ic.y = sqrt(1 - pow(ic.x,2));
ic.z = 0;
}
void solveJ()
{
jc.x = ((kc.y*ic.z) - (kc.z*ic.y));
jc.y = ((kc.z*ic.x) - (kc.x*ic.z));
jc.z = ((kc.x*ic.y) - (kc.y*ic.x));
}
void calcOc(struct vector cam_origin, struct vector one, int f)
{
camera_origin.x = cam_origin.x + (one.x*f);
camera_origin.y = cam_origin.y + (one.y*f);
camera_origin.z = cam_origin.z + (one.z*f);
}
void calcPc(int h)
{
temp.x = posW[h].x - camera_origin.x;
temp.y = posW[h].y - camera_origin.y;
temp.z = posW[h].z - camera_origin.z;
posC.x = (ic.x*temp.x)+(ic.y*temp.y)+(ic.z*temp.z);
posC.y = (jc.x*temp.x)+(jc.y*temp.y)+(jc.z*temp.z);
posC.z = (kc.x*temp.x)+(kc.y*temp.y)+(kc.z*temp.z);
}
/*
void calcPixel(struct vector pos, int f, int no)
{
temp2.x = (f/pos.z)*pos.x;
temp2.y = (f/pos.z)*pos.y;
pixel.x = temp2.x + (M-1)/2;
pixel.y = (N-1)/2 - temp2.y;
int tempo1 = (int) pixel.x;
int tempo2 = (int) pixel.y;
plane[tempo1][tempo2] = no;
}*/