![]() |
The silly syntax errors that won't go away!
We've all been there. You spend hours upon hours working and working on your precious , but when you tell the compiler to finally compile your work, it spits out a error log the size of a Tom Clancy Novel! So you work and work, until the program comes down to one fatal error that you just, cant Find. :ahh:
So that's what this forum is for. Because by the time you actually finish the code, you have lost your ability to spot your own mistakes. Let us help you! :) I'd like the forum to also be open to beginners C programming exploits (aka: not totally robotics related). You learn by doing. :o Errors of any type are welcome! |
Re: The silly syntax errors that won't go away!
Alrighty. I am pretty new to C, though not that new, and I have decided to attempt to try making my own libraries and attached .c files to see how they work. Through much thinking, I have decided to make a program that would simulate a blackjack deck. What I have here isn't very flexible, and it just draws five cards. But when I compile, it says everything in the .h file has been declared twice! I don't know what to do! Here's the code:
main.c Quote:
Quote:
Quote:
|
Re: The silly syntax errors that won't go away!
Quote:
|
Re: The silly syntax errors that won't go away!
Quote:
In the file that needs to own them, in this case deck.c, flank the include statement with #define VAR_DECLARE the include #undef VAR_DECLARE Then in your header file, wrap all the code declaring the variables in #ifdef VAR_DECLARE code goes here #else extern code goes here #endif After the else copy your code defining the variables, but put extern in front of each, that means to the compiler "This is already declared elsewhere, use that version." Example: C file that owns header: Code:
#define VAR_DECLARECode:
#include "header.h"Code:
#ifdef VAR_DECLARE |
Re: The silly syntax errors that won't go away!
actually the more traditional way to do that is
Code:
#ifndef _MY_HEADER_FILE_H_EDIT: forgot to mention that _MY_HEADER_FILE_H_ should be the name of the file it is in (in this case it would be myheaderfile.h), if two files have the same #define at the top, one will get ignored |
Re: The silly syntax errors that won't go away!
Why won't the printf's output anything! It prints temp1: temp2: ground Vector:
aka what's the syntax for outputting doubles @($&^ double calcDistance(void) { double temp1 = 0.0; double temp2 = 0.0; double groundVector = 0.0; printf("temp1: %4.0f ", temp1); if (getTargetFound() == 1){ temp1 = (targetHeight - cameraHeight); printf("temp1: %4.0f ", temp1); temp2 = (getTiltAngle() * 3.14 / 180.0); printf("temp2: %4.5f ", temp2); groundVector = (temp1 / tan(temp2)) * ((temp1) / tan(temp2)); printf("Ground Vector: %f ", groundVector); return groundVector; } else return 0.0; } |
Re: The silly syntax errors that won't go away!
Quote:
|
| All times are GMT -5. The time now is 11:46 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi