Tuesday, February 24, 2009

Input Functions

3 basic types of input functions that receives any value entered from the keyboard (standard input stream).

  • getchar()
  • gets()
  • scanf()
getchar()
This function receives a character type data from the keyboard and stores into a char type variable.
Function syntax:

char variable = getchar();

Example:(outputs in bold are what the user has input)

#include< stdio.h>
int main()
{
char gender;
//prompt for user input
printf("Enter your gender:");
//input function to store data from keyboard into variable gender
gender = getchar();
//displays the gender.
printf("\nGender = %c", gender);

return 0;
}
Output:
Enter your gender:M
Gender = M


gets()

This function receives a string of characters from the keyboard and stores into a character array type variable. Note that the array must be bigger than the number of characters you are going to input.

Function syntax:

gets(char array[]);

Example:

#include< stdio.h>
int main()
{
//declare a character array to store multiple
//letters to form a word.
char name[21];

//prompts user to input data
printf("Enter your name:");
//get the data from keyboard and store into
//variable 'name'
gets(name);
//displays the content of the variable name
printf("\n Your name is %s", name);
return 0;
}
Output:
Enter your name:Programmer
Your name is Programmer

scanf()
This function is used to accept anything, integer numbers, decimal numbers, characters, and character arrays(string).

Function syntax:
scanf("placeholders", inputlist);

Placeholders tell the function what kind of data will be input, and the input list contains which variable to store the data from keyboard into it.

Example:

#include< stdio.h>
int main()
{
//declare int type variable
int mark;
//prompt user to enter mark
printf("Enter your mark: ");
//assigns the value into the variable mark
scanf("%d", &mark);
//display content of variable mark
printf("\nYour mark is %d", mark);
}

Output:
Enter your mark: 89
Your mark is 89

Placeholders will be explained in more detail in the next post.

4 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Unknown said...

Wow, wish you more success. Continue it as good you can anyway it is a good job you are doing.
digital marketing services in india

Unknown said...


"
At the point when all activities and slimming down stage gets fizzled, Keto Primal works splendidly to give the coveted results by giving a thin and sharp body appearance since it is a characteristic craving boosting fat buster. The supplement additionally limits the nourishment desires or enthusiastic eating of people where they would encounter less appetite feel and that would offer them to stay in controlled calorie admission.

The supplement attempts to influence a person to go fit as a fiddle and carry on with a sound and a la mode way of life. The weight reduction process that begins after the admission of the pills go normally, and you may encounter the results inside 2-3 weeks of time. The expansion of every common concentrate here attempts to support the stomach related framework and furthermore clean the colon framework to stay free from hurtful poison squander. It supports the digestion level and gives a lift to vitality and stamina level where you would have the capacity to exercise more without getting worn out and stay dormant way of life. Visit for more informations:
Keto Primal
Health Care 350"

Unknown said...

"I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
Read more here:
kim kardashian sex tape
porn sex video hd
mia khalifa sex video
sunny leone sexy movie"