C's Questions about input scanf and other inputs

Source: Internet
Author: User

Ask:

Why study for more than a year of C language, still do not understand those input function usage, for example: scanf, getch,gets, etc.

For:

Summary from now on 、、、、、

Ask:

It is too late to sum up these basic knowledge, and the others have become great gods.

For:

It's never too late to be aware of your flaws.

"scanf":

1. scanf input integer, with int, float type with%f, double type with%LF.

2. scanf ("%c", ch);

At this point, whether you enter a carriage return, a space, or a tab, it will count as the input of Ch.

3.SCANF ("%s", string);

%s Enter a string with a space, carriage return, tab end, for example: type She is a good girl, then the result of string is she.

and the spaces do not count as string characters.

Add: The mark at the end of string is "".

Char string[100];
scanf ("%s", string);
for (int i=0;string[i]!= ' n '; i++)
printf ("%c", String[i]);
return 0;

If the end condition of the string is changed to "\ n", garbled text will appear because the end condition is not \ n.

Another problem is that you can't enter strings with scanf ("%c", &string[i]).


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.