Home
Programming:
QBasic
C/C++
Commands
Tutorials
FAQ
Links
Math
Web Dev:
HTML
PHP
Other:
Links
Downloads
Projects
Contact:
Chatroom
Guestbook
Email Me

Site Meter
Of course, a logo should be here.

C Section - FAQ

FAQ stands for "Frequently Asked Questions". I searched many forums while looking for frequently asked questions. This page has those questions, and it has the questions' answers.

Try to find your question in the table below, and click on it for the answer. If you can not find your question, e-mail it to me.

Information on the C Language:
 What is C?
 What is C good for?
 Where can I get a C compiler?
Questions on Using C:
 How do I compile something?
 How do I use libraries?
File FAQ:
 How do I get a list of files?
 How do I test for the existence of a file?
Converting:
 Decimal to Binary
 Binary to Decimal
 Decimal to Roman Numerals
 Roman Numerals to Decimal

What is C? top

C was created nearly fourty years ago at the Bell Telephone Laboratories. Since then, it has become one of the most popular programming languages. C is cross-platform (it can be written to run on any OS) and can be used to make just about anything wich makes it one of the most powerful languages as well.


What is C good for? top

Better yet, what is C not good for? I suppose the only thing that C lacks in is graphics. Graphics can be done easily in C, but I think some other languages do have it beat there. For everything else, C or C++ seems to be the best in my opinion.


Where can I get a C compiler? top

The best C compiler and editor that I have used is Bloodshed's Dev-Cpp which comes with the mingw compiler. The best compiler, period, that I have used is Microsoft Visual C++, but it costs a bit of money.


How do I compile something? top

It differs slightly with each compiler. If you have an editor, It may have a menu option you can select or a button you can click to compile something. You can also use the command line to compile. There should be documentation that comes with the compiler that will tell you how to use it.

In Microsoft Visual C++, go to Debug–>Start or Debug–>Start Without Debugging. For the command line in Microsoft Visual C++, type cl file.c.

In Bloodshed's Devcpp, go to Execute–>Compile, click Close when it finishes, then go to Execute–>Run. To compile from the command line, type g++ file.c -o file.exe.

For other compilers, look in the documentation that comes with them.


How do I use libraries? top

This differs slightly with each compiler. If you have an editor, it may have a menu option you can select or a button you can click to compile something. You can also use the command line to compile. There should be documentation that comes with the compiler that will tell you how to use it.

In Microsoft Visual C++, go to Project–>[project] Properties, click Linker, click Input, place your cursor in the Additional Dependencies box, then type in the names of the libraries you wish to use (don't forget the .lib extention). For the command line in Microsoft Visual C++, type cl file.c library1.lib library2.lib.

In Bloodshed's Devcpp, go to Project–>Project Options, click Parameters, then, in the linker field, enter the libraries you wish to use. To use the command line to compile with libraries, type g++ file.cpp library1.lib library2.lib. I'm not sure if I'm right about the syntax of the mingw compiler. Someone please verify the information in this FAQ.

For other compilers, look in the documentation that comes with them.


How do I get a list of files? top

To get a list of files, use the system() function to execute the command prompt command "dir/b/a-d >List.lst". Then, just read in the files from List.lst. Don't forget to delete the List.lst file after you are finished with it. To get a list of directories instead of files, send "dir/b/ad >List.lst" to the command prompt instead. The following code prints out the files in the current directory.


How do I test for the existence of a file? top

It's pretty easy. You just open the file using fopen(). If fopen() returns NULL, the file can't be opened, so it probably does not exist.


How do I convert Decimal to Binary? top

Before you learn how to convert between bases, you need to understand our standard 10-base number system better. Every number can be represented in the form a*10^0 + b*10^1 + c*10^2 + d*10^3..., where a, b, c, and d are digits. For example, 397 = 7*10^0 + 9*10^1 + 3*10^2.

Our number system is base-10 and that is where the 10^0, 10^1, 10^2, etc. comes from. Binary numbers' only difference is that they can be represented in the form p*2^0 + q*2^1 + r*2^2 + s*2^3..., where p, q, r, and s are digits. For example, 111 in binary (7 in decimal) is 1*2^0 + 1*2^1 + 1*2^2.

To convert 14 (decimal) to a binary number, use this method:
14 / (2^3) = 1, remainder 6Pick the highest power of 2 that will divide into the number.
6 / (2^2) = 1, remainder 2Take the remainder and divide by the next lowest power of 2.
2 / (2^1) = 1, remainder 0
0 / (2^0) = 0, remainder 0Keep repeating until you are dividing by 2^0 is 0.
The answer is the answer to the math operations above (1, 1, 1, and 0). 14 in binary is 1110.

Similarly, to convert 379 into binary:
379 / (2^10)2^10 is too high (1024), let's try a smaller number.
379 / (2^9)2^9 is still too high (512), try again...
379 / (2^8) = 1, remainder 1232^8 works, so let's start here.
123 / (2^7) = 0, remainder 123Divide the remainder by the next lowest power of 2
123 / (2^6) = 1, remainder 59
59 / (2^5) = 1, remainder 27
27 / (2^4) = 1, remainder 11
11 / (2^3) = 1, remainder 3
3 / (2^2) = 0, remainder 3
3 / (2^1) = 1, remainder 1
1 / (2^0) = 1, remainder 0Keep repeating until you are dividing by 2^0
The answer is the answer to the math operations above: 101111011.

Another way you can figure out the last digit is to look at the remainder of the division by 2^1. When you are converting decimal to binary, the remainder of the 2nd from last step and the answer to the last step will be the same.

I have included an example program that converts decimal to binary. The maximum is a 32-bit integer (largest can be 4294967295). You will have to modify the program to handle larger numbers.


How do I convert Binary to Decimal? top

Before you learn how to convert between bases, you need to understand our standard 10-base number system better. Every number can be represented in the form a*10^0 + b*10^1 + c*10^2 + d*10^3..., where a, b, c, and d are digits. For example, 397 = 7*10^0 + 9*10^1 + 3*10^2.

Our number system is base-10 and that is where the 10^0, 10^1, 10^2, etc. comes from. Binary numbers' only difference is that they can be represented in the form p*2^0 + q*2^1 + r*2^2 + s*2^3..., where p, q, r, and s are digits. For example, 111 in binary (7 in decimal) is 1*2^0 + 1*2^1 + 1*2^2.

To convert 1010 in binary into decimal, just rewrite 1010 in the alternate form and solve: 0*2^0 + 1*2^1 + 0*2^2 + 0*2^3 = 10.

To convert 101110 in binary into decimal, rewrite 101110 in the alternate form: 0*2^0 + 1*2^1 + 1*2^2 + 1*2^3 + 0*2^4 + 1*2^5 = 46.

The following is an example program that converts binary to decimal. The maximum is a binary number with 32 digits.



How do I convert Decimal to Roman Numerals? top

The easiest way to convert between decimal and Roman numerals is to use a lot of if commands. I have included an example that uses this way. The maximum decimal number that it can accurately convert is 4000.


How do I convert Roman Numerals to Decimal? top

The easiest way to convert Roman numerals to decimal is to use a lot of if commands and variables to hold each decimal place. I have included an example that uses this way. The maximum Roman numeral that it can convert is MMMMDCCCCLXXXXVIII.