answersLogoWhite

0

Why you use scanf?

User Avatar

Anonymous

14y ago
Updated: 8/18/2019

scanf is a function that reads data with specified format from a given string stream source, originated from C Programming language, and is present in many other programming languages.

The scanf function prototype is:

int scanf(const char *format, ...);

The function returns the total number of items successfully matched, which can be less than the number requested. If the input stream is exhausted or reading from it otherwise fails before any items are matched, EOF is returned.

So far as is traceable, "scanf" stands for "scan format", because it scans the input for valid tokens and parses them according to a specified format.

Usage

The scanf function is found in C, in which it reads input for numbers and other datatypes from standard input (often a command line interface or similar kind of a text user interface).

The following shows code in C that reads a variable number of unformatted decimal integers from the console and prints out each of them on a separate line:

#include

int

main(void)

{

int n;

while (scanf("%d", &n) 1)

puts(word);

return 0;

}

No matter what the datatype the programmer wants the program to read, the arguments (such as &nabove) must be pointers pointing to memory. Otherwise, the function will not perform correctly because it will be attempting to overwrite the wrong sections of memory, rather than pointing to the memory location of the variable you are attempting to get input for.

As scanf is designated to read only from standard input, many programming languages with interfaces, such as PHP, have derivatives such as sscanfand fscanf but not scanf itself.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Can you use scanf function within printf function?

Yes: double d; printf ("scanf's just returned %d\n", scanf ("%lf", &d));


Why not use the ampression symbol in scanf statement in function?

scanf is a function, not a statement. Example: int a; char name[12]; scanf ("%d %s", &a, &name[0]);


Scanf function in c for strings?

Use '%s', eg: char name[64]; scanf ("%s", name);


What is the use of printf and scanf function?

Printf prints something to the standard output stream, and scanf inputs something from the standard input stream.


Why do you use scanf in c?

To read input from standard input.


What is return type of scanf function?

Use the help/manual.


What is difference between scanf and cin?

scanf is a function (available in C and C++)cin is an istream object (C++ only)Advice: when in doubt, use fgets+sscanf


How do you use scanf with delimiter in c plus plus Please provide a basic example with output?

scanf does not employ a delimiter. It simply reads formatted input from std::cin.


Can you use scanf to get a string to a c program?

Certainly. That's what sequence %s is good for.


How can we read two strings using c program?

#include,stdio.h>main(){char string1[20],string2[20]printf("enter the first string");scanf("%s",string1);// reading the string1printf("enter the second string");scanf("%s", string2);// reading the the string2printf( "the first string is %s",string1);// printing the string1printf("the second string is %s",string2);// printing the string2}the problem of using scanf is that it does not take space. so we can use gets for it.ie instead of scanf("%s",string1); we can use gets(string1); .


Scanf in java?

There is no scanf in Java. It is one of the keywords used in C Programming language


C program to accept a sentence using scanf?

scanf ("%[^\n]s", sentence);