smokeyangel, you okay and sober? Lots of typos..
bgibs24, you should always provide enough code to compile. It does not have to be a full program (no need to have main()), but it should compile and produce the exact error you're seeing in your project.
As to your original problem, consider this example program:
Code:
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
typedef uint32_t pixel;
typedef struct {
double x;
double y;
} vec2d;
typedef struct {
double x;
double y;
double z;
} vec3d;
typedef struct {
double x;
double y;
double z;
double w;
} vec4d;
typedef struct {
int screen_width;
int screen_height;
vec3d location;
vec3d target;
vec3d up;
vec3d right;
pixel *image;
} camera;
int main(void)
{
camera cam1;
camera *cam2;
cam2 = malloc(sizeof *cam2);
if (cam2 == NULL) {
fprintf(stderr, "Not enough memory.\n");
return EXIT_FAILURE;
}
if (fscanf(stdin, " %lf %lf %lf", &(cam1.location.x), &(cam1.location.y), &(cam1.location.z)) != 3) {
fprintf(stderr, "No cam1 location specified.\n");
return EXIT_FAILURE;
}
if (fscanf(stdin, " %lf %lf %lf", &(cam2->location.x), &(cam2->location.y), &(cam2->location.z)) != 3) {
fprintf(stderr, "No cam2 location specified.\n");
return EXIT_FAILURE;
}
printf("cam1 location is (%g, %g, %g)\n", cam1.location.x, cam1.location.y, cam1.location.z);
printf("cam2 location is (%g, %g, %g)\n", cam2->location.x, cam2->location.y, cam2->location.z);
return EXIT_SUCCESS;
}
Note that %lf is the pattern to scan a double, but you use %f to print one. When you print a float (which you can scan using %f), it is actually promoted to double type.
To scan a long double, you use %Lf or %llf , and %Lf to print.
There are actually quite a few formats and specifiers you can use too, documented at the printf() and scanf() man pages, but these two happen to be the two densest man pages, and so are not the easiest to read for new programmers. But they do help when you write new code or test functionality.
Questions?