The use of scanf function in C language gets rain

Source: Internet
Author: User

/*1. Different points:
SCANF cannot accept space, Tab tab, carriage return, etc.;
And get can accept space, Tab tab and enter, etc.;
2. The same point:


The string is automatically added after the end of the acceptance. With scanf ("%s", &s), there is a problem with the function input string, that is, if a space is entered to assume that the string ends, the character after the space is processed as the next entry, but the Get () function will receive the entire string of input until it encounters a change in behavior.

#include "stdio.h"
#include "string.h"
int l1=0,l2=0; L1 number of lowercase letters, number of L2 capitals
Main ()
{
void Str (char,int);
Char c[100];
int length;
printf ("Please input a string");
/* SCANF ("%s", c); */
Gets (c);
Length=strlen (c);
STR (c,length);
printf ("Number of lowercase letters:%d, capital letters:%d\n", L1,L2);
}
void Str (char b[],int N)
{
int i;
for (i=0;i<n;i++)
if (' A ' <=b[i]&&b[i]<= ' z ') l1++;
else if (' A ' <=b[i]&&b[i]<= ' Z ') l2++;
else if (b[i]= ') continue;
}

C language Gets rain scanf function usage

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.