All in one forum  - Applications | Games | E-Books | Music, Movies & Videos | Mobile Stuff | Live Discussions | Webmaster Stuff | Many More | Community to Hang Out and Stick to
Search Today's Posts Mark Forums Read

Go Back   Home > Tutorial Section > Programming > C and C++
Reload this Page C Functions
Forgot Password? Join Us!
C and C++ Post your C and C++ Related Tutorial Here

Notices
Your link here Your link here Your link here Your link here Your link here

Your Ad Here


Rate This Thread - C Functions.

Post New Thread Reply
Bookmarks
 
LinkBack Thread Tools Display Modes
Old 01-04-2008, 05:20 PM   #15 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function puts()

Function puts will display a single string of text on its own line. The string can be a variable or a string constant (text in closed in parenthesis). This function has no special formatting capabilities like printf does. Here is the format.
puts("This will appear on it's own line");
//or
puts( string );
Either way will result the string being on its own line. To use puts you need the stdio.h header file.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Click here to Donate to remove the Adverts.
Your Ad Here
Old 01-04-2008, 05:20 PM   #16 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function rand()

The rand function is used to get random numbers from the computer. It returns an integer value, but does not take an parameters. It is is used like this:
x = rand();
The value that rand returns is in a range form 0 to (at least) 32,767. This range could be larger depending on the specification in the stdlib.h (standard library) file. Most of the time this range will probably be too large for what you want. For example, if you are writing a program that simulates dice, you probably don't want a roll of 11,713. To set a better range, use the modulus operator (%). It should look like this.

x = rand() % 10;
The modulus operator takes two numbers, and divides them. But rather than giving you the result of that division, it gives you the remainder. So 24 % 10 (read twenty-four mod ten) would result in an answer of 4. The result will always be from 0 (if the numbers divide evenly) and one less than the number on the right. In this case 0-9. In the example, rand returns a number (probably a huge number). Then the modulus operator is used to cut it down to a range of 0 to 9. To change the range to 1 to 10, simply add one the result. To make the range 0 to 10, change the 10 to an 11.
The rand function gets numbers from your computers random number generator. The random number generator needs to be set up in order to work properly. You do this with the srand function. That function should be called before rand is ever used. If you forget to do that you may find that you are getting the same "random" numbers every time!
To use the rand function you must include the stdlib.h file.

TECHNICAL NOTES

*Random numbers from the random number generator are not really random, they are pseudorandom.
*That means they are not really random, but it is close enough.
*The random number generator selects numbers in a uniform distribution from 0 to 1, with a mean average of .5 and a standard deviation of .25.
*I'm not sure why I bothered with that last one.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Click here to Donate to remove the Adverts.
Your Ad Here
Old 01-04-2008, 05:20 PM   #17 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function scanf()

The scanf function is used to read information from the keyboard. To use scanf you need a place to store the information, and the scanf function itself. Here is the proper format for using scanf.
scanf("%d",&var);
Scanf does not display anything, the contents of the quotes are the conversion character representing the variable you want to store. You must always use the ampersand before the variable name. Of course, the type of the variable you are using to store the input must be the type represented by the conversion character. After you get the input, you may use it however you want. For example,
#include <stdio.h>

int main()
{
int x;

puts("Enter a number");
scanf("%d",&x);
printf("You typed %d \n",x);

return 0;
}
This should give you these results:

Enter a number
5
You typed 5
NOTE: Users must press enter after they type their scanf info.
This is a perfectly good use for scanf. But, if you don't match the conversion character with the variable type, you'll have bad things happen. In fact, your compiler may not even tell you what you did wrong! As was showed in the first lesson on input, scanf can be used to get a string. You should probably take a little time and try using scanf with some if it's other conversion characters.

RETURN VALUE OF SCANF

Like printf, scanf has a return value too. It is also an integer, and the value of that integer is the number of things scanf read. With an integer, called count, already declared, we can do this
count = scanf("%d%d",&x,&y);
Count should equal 2, if it does not, then scanf did not work correctly. Testing this value is often helpful in finding errors. TECHNICAL NOTES

*What's up the ampersand (&) thing in scanf? Scanf needs to know the address of the variables it is using. That is what the ampersand does. When it is put in front of a variable in C, we are saying this is the address of this variable, not the value. The address of a variable is the location of the variable in your computers memory not the value.
*The f in scanf stands for formatted, just like in printf.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-04-2008, 05:21 PM   #18 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function sqrt()

The sqrt function finds the square root of a number. It takes one parameter (the number you want the square root of) and returns a double. The return value will be the square root of the parameter. A call to sqrt might look like this.
answer = sqrt( 841 );
Answer should equal 29. And that's how you get a square root. Remember that sqrt returns a double. So, if you use an integer, or even a float to store the return value, you will probably get warnings from the compiler about a possible loss of data. If you use a float you will only loose data if the number of decimal places in the answer is huge! If you use an integer you will loose all decimal places.
To use this function include either math.h or stdlib.h depending o your compiler.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Click here to Donate to remove the Adverts.
Your Ad Here
Old 01-04-2008, 05:21 PM   #19 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function srand()

Srand stands for seed random. The srand function is use to set up the random number generator. It does not have a return value, but it does require a parameter. It needs and unsigned int. When srand is called it will use the number passed to it to seed a set of random numbers. To get different random numbers, you must pass srand different values for it's parameter. A call to srand looks like this.
srand( 997 );
To get truly random numbers, we must use a random seed. The most common way to use the srand function is to pass the current system date. The system date can be obtained with the time function. Time will return the current date (down to the microsecond) in the form of a single number. Here is an example.
srand( time(NULL) );
First the time function will be called, and it will return the time, which will then be passed as a parameter to the srand function. You need to use this function call before you use the rand function. To use the srand function you must include stdlib.h. To use the time function you need to include time.h
TECHNICAL NOTES

*See the technical notes section of the rand page for a brief discussion of random number generators.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-04-2008, 05:21 PM   #20 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function strcat()

The strcat function (string concatenate) takes two strings and combines them into one. It takes two parameters, both strings. The second string gets stuck on the end of the first string. You need to be sure you have enough room in the first string to hold itself, plus the second string. The format looks like this.
strcat( start, end );
Start and end are both strings. End can be a string constant (text in double quotes). When strcat is done, start will have end pasted to the end of it. Here is a real example.
//start = "Hi, "
//end = "Mom!"
strcat( start, end );
The results would be that start would equal "Hi, Mom!", and end would still equal "Mom!." For strcat to work you must include the string.h header file.

TECHNICAL NOTES

*Concatenate - "Kon-Kat-un-ate" to string things together.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Click here to Donate to remove the Adverts.
Your Ad Here
Old 01-04-2008, 05:22 PM   #21 (permalink)
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 26
Achievements Posts: 10,268
Casino Cash: $1066420

Total Points: 236,720,619,382.51
Donate

Reputation: 90403
KoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond reputeKoOL has a reputation beyond repute


Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
Function strcmp()

The strcmp function (string compare) compares two strings based on alphabetical order. It takes two parameters, which are both strings. It returns an integer value. The integer is the result of the comparison. If the strings are equal, zero will be returned, if the first string is greater (later in the alphabetical order) then one will be returned. If the second string is greater, then negative one will be returned. Here is the format.
result = strcmp( string1, string2 );
//or
result = strcmp( string1, "string2");
//or even
result = strcmp( "string1", string2 );
As with many string functions one of the parameters can be a string constant. I guess both could be string constants if you wanted, but that would be kind of silly. The strcmp function is case sensitive so a string that started with 'A' would be greater than a string that started with 'a'. Upper case characters come before lowercase. To ignore the case of strings use the strcmpi function. It does the exact same thing, except it ignores (that's what the i is for) upper and lower case differences. Some Unix compilers may not have strcmpi.
For strcmp to work you must include the string.h header file.

For Download Links U need to Press Thanks Button
My Goal 2: (Complete 10000)

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
KoOL is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply
Click here to Donate to remove the Adverts.
Your Ad Here
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump