I am attempting to find the setting so that if the correct header file is not included for various functions (atof, strlen, etc.) an error will be generated. Currently the code compiles and links, but the results are odd since the correct information is not included.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Post your compile log, and let us see! The default options I believe will warn
you, so you must have set something to suppress it. In C++ absence of a
declaration before use is an error in any case, in C it is legal, but the
assumptions the compiler then makes are not likely to be correct in all cases,
and it will perform no checking of argument types.
One other possibility is that you have included a header that indirectly
includes others. For example many C++ headers include underlying C library
headers. Unfortunately, it is both implementation dependent, and uncheckable.
The preprocessor inserts the included text, by the time the compiler sees it
as a single compilation unit, it all looks good.
Anyway, you really should post an example of code that produces teh problem,
and the associated Compile Log text - All of it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
{
/x is declared as a float/
float x=0;
int store;
x= getamount();
printf("%d\n", x);
/scanf specifies data being entered for the value of x/
printf("\nEnter 1 for DelMar, 2 for LaJolla, 3 for Encinitas: ");
scanf("%d", &store);
if (store == 1)
/print tax amount for DelMar Store/
printf("DelMar: %f \n", x1.0725);
else if (store == 2)
/print tax amount for LaJolla Store/
printf("LaJolla: %f \n", x1.0775);
else if (store == 3)
/print tax amount for Encinitas Store/
printf("Encinitas: %f \n", x*1.0750);
Never mind, it will take us all a while to get used to this new forum composer
(just started using the identical one on , so I am a bit ahead perhaps). The
trick is to paste the text, then re-select it, then click the format button.
There is now also a live preview at the bottom so you can check it as you go
(or at least before posting)
Put the log in code format too would be useful.
I think you could have posted a smaller example - perhaps one call and no
header?
To the question:
What is is you believe you should get warnings for? isdigit() <ctype.h>
and atof() <stdlib.h> as far as I can see.
I no longer use Dev-C++ so I cannot try it, but I recommend that you use the
following options in all cases:
-Wall -Wformat -Werror
-Wformat is useful for stdio formatted I/O checking. In later versions of GCC it is implied by -Wall, but not in teh rather old GCC shipped with Dev-C++.
Another point ##
I find it bizarrre that you would build code in "Temporary Internet
Files", but beyond your personal preference for file misorganisation,
project paths containing paths on occasions cause problems with builds in
Dev-C++. Don't do it. Also Windows Disk Cleanup, or a browser cache clear-out
would probably have the effect fo deleting all your hard work!
I am attempting to find the setting so that if the correct header file is not included for various functions (atof, strlen, etc.) an error will be generated. Currently the code compiles and links, but the results are odd since the correct information is not included.
Post your compile log, and let us see! The default options I believe will warn
you, so you must have set something to suppress it. In C++ absence of a
declaration before use is an error in any case, in C it is legal, but the
assumptions the compiler then makes are not likely to be correct in all cases,
and it will perform no checking of argument types.
One other possibility is that you have included a header that indirectly
includes others. For example many C++ headers include underlying C library
headers. Unfortunately, it is both implementation dependent, and uncheckable.
The preprocessor inserts the included text, by the time the compiler sees it
as a single compilation unit, it all looks good.
Anyway, you really should post an example of code that produces teh problem,
and the associated Compile Log text - All of it.
... oh an note that now SourceForge has entered teh 21st Century at last and
supports "Markdown" syntax mark-up, use the code formatting; like
this:
int main()
{
...
}
Brilliant! How long we have waited.
Here is the code:
include <stdio.h>
include <math.h>
float getamount()
{
char sAmount;
int x = 0;
char cResponse = 't';
int deci = 0;
float amount;
printf("\nEnter purchase amount (max length 15): ");
scanf("%s", sAmount);
fflush(stdin);
for(x=0; x<strlen(sAmount); x++)
{
if(!isdigit(sAmount))
{
if(sAmount!='.')
{
cResponse = 'f';
}
else
{
deci++;
}
}
}
if(cResponse == 'f' || deci > 1 || (amount = atof(sAmount)) == 0.0)
amount = -1.0;
printf("sAmount = %s\n", sAmount);
printf("amount=%f\n", amount);
return(amount);
}
int main()
{
/x is declared as a float/
float x=0;
int store;
x= getamount();
printf("%d\n", x);
/scanf specifies data being entered for the value of x/
printf("\nEnter 1 for DelMar, 2 for LaJolla, 3 for Encinitas: ");
scanf("%d", &store);
if (store == 1)
/print tax amount for DelMar Store/
printf("DelMar: %f \n", x1.0725);
else if (store == 2)
/print tax amount for LaJolla Store/
printf("LaJolla: %f \n", x1.0775);
else if (store == 3)
/print tax amount for Encinitas Store/
printf("Encinitas: %f \n", x*1.0750);
getch();
return 0;
}
and here is the compile log
Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Users\Scott\AppData\Local\Microsoft\Windows\Temporary
Internet Files\Low\Content.IE5\CF8VH8CK\Week+4+Assignment.c" -o
"C:\Users\Scott\AppData\Local\Microsoft\Windows\Temporary Internet
Files\Low\Content.IE5\CF8VH8CK\Week+4+Assignment.exe" -g3 -I"C:\Dev-
Cpp\include" -L"C:\Dev-Cpp\lib" -g3
Execution terminated
Compilation successful
The code is a C code file (.c)
Sorry, the cut and paste didn't keep the format very well. If needed, I can do
it again and edit the paste.
Never mind, it will take us all a while to get used to this new forum composer
(just started using the identical one on , so I am a bit ahead perhaps). The
trick is to paste the text, then re-select it, then click the format button.
There is now also a live preview at the bottom so you can check it as you go
(or at least before posting)
Put the log in code format too would be useful.
I think you could have posted a smaller example - perhaps one call and no
header?
To the question:
What is is you believe you should get warnings for? isdigit() <ctype.h>
and atof() <stdlib.h> as far as I can see.
I no longer use Dev-C++ so I cannot try it, but I recommend that you use the
following options in all cases:
-Wall -Wformat -Werror
-Wformat is useful for stdio formatted I/O checking. In later versions of GCC it is implied by -Wall, but not in teh rather old GCC shipped with Dev-C++.
Another point ##
http://stackoverflow.com/
... Oh well it was too much I guess to expect SourceForge to get
"markdown" correct, the quote mark-up failed to work completely!