Leak Society - The Home Of Nulled Resources.
Forum Beta v1 Now Live!
C/C++
Thead Owner : Kurt Manion, Category : Everything Coding, 14 Comment, 442 Read
Viewers: 2 Guest(s)
Member
***
167
Messages
19
Threads
0
Rep
4 Years of Service
08-16-2011, 04:16 PM
#8
tut3
writing an application.

now here's the good stuff
Code:
int main()
{
printf("hello world\n");
}
the first thing a C (notice I didn't say C++)program executes is it's main function. it's execute what's in-between the
curly braces. our program also incorporates a printf statement which is just like the print statement in GM. except with different syntax
this will print hello world to the consol, and then make a newline. That is what the character \n is. it's the newline character. the compiler treats
this as a single character much like a, or b. but when encountered instead of writing it, it makes a newline. the backslash starts all special characters such at this
to write a real backslash write //
also considered one character
printf statements can also take variable as arguments and print them
Code:
int x = 1;
main()
{
printf("%d", x);
}
this prints x in decimal form (hence the d)
there are many other character converters, and even modifiers to them.

one more thing I'd like to say on this. if you actually typed this into the compiler and ran it, you should see some annoying warning telling you main() epaulets to int.
now you should be mildly confused because I didn't tell you about returning values. main will ALMOST always return an int.
0 for: every line of code has been finished so I'm going to quit incorrectly now!
1 for: got it I just received the quit command
so the program should look like this
Code:
int x = 1;
int main()
{
printf("%d", x);
       return(1);
}
the parenthesis aren't necessary, but a convention.

part 2:
scanf:

scanf has similar syntax to printf, but it read for info from the user
Code:
int d;
int main()
{
scanf("%d", &d);
printf("%d", d);
}
scanf looks for an integer the user writes, and then writes it again(on a new line)
simple, and versatile concept.

now I have a challenge for all of you.

if temperature can be converted from fahrenheit  to celsius by the equation C=(F - 32)/1.8
then program a program to ask the user for the temp in fahrenheit and then writes it in Celsius.
post it here, and I'll comment on all the good and bad.
even if your program doesn't work still upload it.
P.S. make sure to keep it, because we'll be doing something else with it latter.


Messages In This Thread
C/C++ - by Kurt Manion - 08-12-2011, 12:35 AM
C/C++ - by Taz - 08-13-2011, 07:57 PM
C/C++ - by Gan - 08-13-2011, 08:16 PM
C/C++ - by Kurt Manion - 08-14-2011, 12:57 PM
C/C++ - by Kurt Manion - 08-14-2011, 12:59 PM
C/C++ - by Kurt Manion - 08-16-2011, 04:09 PM
C/C++ - by Kurt Manion - 08-16-2011, 04:10 PM
C/C++ - by Kurt Manion - 08-16-2011, 04:16 PM
C/C++ - by Kurt Manion - 08-16-2011, 05:06 PM
C/C++ - by Kurt Manion - 08-27-2011, 11:08 PM
C/C++ - by Kurt Manion - 09-04-2011, 09:01 PM
C/C++ - by Kurt Manion - 09-05-2011, 03:38 PM
C/C++ - by Kurt Manion - 09-08-2011, 09:00 PM
C/C++ - by Kurt Manion - 09-19-2011, 09:57 PM
C/C++ - by Kurt Manion - 09-22-2011, 10:49 PM

Forum Jump: