scan() Function

scanf("format string",argument_list); 
  • The scanf() function is used for input. It reads the input data from the console.
  • The first ("%i") specifies what type of data type is expected (char, int, or float). 
  • The second argument (&number) specifies the variable into which the typed response will be placed.
  • In this case the response will be placed into the memory location associated with the variable number.
  • In C programming, when you use the & (ampersand) character, it is known as the "address-of" operator. It provides the memory address where a variable is stored. Understanding this is crucial for scenarios where you want to manipulate or interact with the actual memory location of a variable. 
In programming languages like C, input from users via keyboard input is commonly achieved using the `scanf()` method. However, there are scenarios where formatted data needs to be read from one string into another rather than directly from the keyboard. This is where the `sscanf()` method comes into play. Unlike `scanf()`, which reads input from the standard input (keyboard), `sscanf()` is used for parsing formatted strings from existing strings. It allows for the extraction and assignment of values from one string to another or the breaking of a single string into multiple parts. For example, if we have a string like "hi to the world," `sscanf()` can be employed to extract and store this string into three other strings or variables. This function provides flexibility for manipulating and extracting structured information from strings, offering a useful tool for various programming tasks.

Ask from user to input a value and then assign that value.
#include <stdio.h>
int main()
{
    int number;
    printf("Type in a number : ");
    scanf("%i", &number);
    printf("The number you typed was %i\n", number);return 0;
}

Comments

Popular posts from this blog

Tutorial 11 & 12

Format Modifiers (Format Specifiers)

Simple and basic C program code