End of input array of C

Source: Internet
Author: User

I've seen a variety of input requirements from the moment you touch the code to the present, such as:

1. Enter a line of numbers, ending with-1

2. Enter the string to end with a carriage return

3. Enter 10 digits

Wait a minute

Sometimes it is these basic input problems that hinder the steps of understanding the problem.

The rest of the time did not think that today try to enter a string of numbers into an array, ending with 1

"Code Instance"

int array[1000];
int i=0;
while (Array[i-1]!=-1)
{
scanf ("%d", &array[i++]);
}

It is worth noting that I always thought that while the condition is the array "I"! =-1, if this is the case, each time the loop body input a number, I will add one, so again to judge, the array "I" is not equal to-1, even if the last input is 1, so this input is like chewing a bright mai, can not stop at all.



The input string is the same.

"Code Instance"

Char a[1000];
int i=0;
while (a[i-1]!= ' \ n ')
{
scanf ("%c", &a[i++]);
}

The same thing, just changing the input string.


That's all for the time being, ready to update.

End of input array of C

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.