The return value of the scanf,printf function

Source: Internet
Author: User

Reference from: https://www.douban.com/note/220299804/

There are three scenarios for the return value of the scanf function:

(1) The first is to return a positive integer representing the number of successful elements entered.

(2) The second type if the value returned is 0, which means that the input mismatch does not correctly enter any value, so the following code is available.

(3) The third return-1 (EOF) is the end of the input stream. Windows:ctrl + Z means end of input, Linux:ctrl + D.

The return value of the printf function is the number of output elements.  printf ("%d\n", 1); 2

#include <stdio.h>#include<string.h>intMain () {intnum[ -];  for(inti =0; I <Ten; i++)//input:1 2 3 4?? 6 7 8 9 0    {        if(SCANF ("%d", &num[i]) = =0) {scanf ("?"); Num[i]= -1; }    }     for(inti =0; I <Ten; i++)    {        if(I! =0) printf (" "); printf ("%d", Num[i]); } printf ("\ n");//output:1 2 3 4-1-1 6 7 8 9 0    return 0;}

Plus one:

The storage of the two-dimensional array in memory is continuous, so there is the following code.

#include <stdio.h>#include<string.h>intMain () {intLen; Charstr[Ten][1]; scanf ("%s", str[0]);//ABCDELen = strlen (str[0]); printf ("%d", Len);//5 Because the storage of two-bit arrays is contiguous in memoryPuts (str[0]);//ABCDE    return 0;}

The return value of the scanf,printf function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.