top of page

Scanf

Scanf will be used to supply user input in C programming. When the program is executed the function will pause at a scanf function and wait for the user to type their input, after which it will continue. The scanf syntax is similar to printf but slightly modified;

An addressOf operator & will be used. This is because scanf uses pointers as arguments instead of variable names. While working with arrays however, the addressOf operator is unnecessary.

For standard variables: scanf("%i",&var);                                             For array variables: scanf("%s",var);

Output:

scanf2.png

Example:

scanf1.png

Multiple inputs may be taken simultaneously in one function, this will use the format: scanf("%i%i",var1,var2);

This allows us to type both inputs in with a whitespace between them. The whitespace is the default delimiter used by scanf to separate inputs, we will look at changing the delimiter later on.

scanf4.png

Output:

Example:

scanf3.png
  • Twitter
  • LinkedIn
  • discord-logo--v2
  • kisspng-github-pages-logo-repository-fork-github-logo-1-magentys-5b69de71b51265

Dragon Eye Intelligence LLC

bottom of page