Hey guys. Thanks for taking the time to read this post.
I'm relatively comfortable with C++ and am taking a class in C for the first time. I'm finding it difficult and frustrating to adapt to the new language. It's kind of like trying to box with a hand tied behind my back.
At any rate, I have a few general questions and a few specific questions that might help me to better understand general and specific aspects of the language . Feel free to tackle the questions that you'd like.
Is C a subset of C++? Do they share libraries? Are there libraries that are specific to C or C++?
Part of the reason I'm having trouble with C is that I'm finding it difficult to search for answers online. With C++ I can just include the phrase "C++" on any question and I'll arrive at a destination.
With C, however, I'm really not sure what combination of words to add to my search. "C programming," "C language," "C," Any advice?
Additionally, are there any websites that you can point me to for general information on C?
http://www.cprogramming.com/ seems to have some of the information that I'm looking for.
Also, I'm having trouble with a specific piece of code.
This is a homework assignment to explain the relationships between two numbers through addition, subtraction, multiplication, division, and % (modulus?). I'm not sure if it matters, but I work in Cygwin.
The problems I'm encountering are with division and modulus. The numbers that I am using are 5 and 10, respectively.
The output that the program gives me is as follows:
> 5 / 10 = 0.000000.
> 5 %d = 10.
I'm looking for an answer of .5 and 5(?).
I'm pretty sure that this has something to do with variable types; but changing the variable types in the declarations does does not produce the results that I'd like.
#include <stdio.h>
int main(void)
{
int num1;
int num2;
float div;
int mod;
printf("> Please enter an integer and hit the [Enter] button.\n> ");
scanf("%d", &num1);
printf("\n> Please enter another integer and hit the [Enter] button.\n> ");
scanf("%d", &num2);
// division
div = num1 / num2;
printf("> %d / %d = %f.\n", num1, num2, div);
// remainder
mod = num1 % num2;
printf("> %d % %d = %d.\n", num1, num2, mod);
return 0;
}
Additionally, how can I display the "%" character without sabotaging my printf(); command?
That would be in this section of code:
printf("> %d % %d = %d.\n", num1, num2, mod);
I really want to learn this language; I just need a push in the right direction. Thank you for reading.
- LordoftheFly