when you use double type to count, it will be dangerous. see like that
[codesyntax lang=”c” tab_width=”2”]
1 2 3 4 5 6 7 8 | |
it will never stop, because the condition of i != 5 will never satisfied. If you want to count, using int type. When you compare two double type number, you should use fabs(a-b) < 0.001, 0.001 is threshold. Sometimes, double is not precision. macro is a great tool, but it is also dangerous. I often forget the language of define. The correct language is :
define
if defined
if !defined
ifndef
ifdef
endif
compile .c file with math lib in linux. It will be like that: cc test.c -o test -lm
stdio redirect to file use freopen() function. like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
if you want redirect to file, use the code and compile it with -D REDIRECT. cc test.c -o test -D REDIRECT
If you want to use struct FILE to do the same thing:
[codesyntax lang=”c” tab_width=”2”]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
try cc t3.c -o t3 -lm -D REDIRECT and cc t3.c -o t3 -lm