Programming finds the longest word in a known string, assuming that the string contains only letters and spaces, separating the words with spaces.

Source: Internet
Author: User
    Char str[255] = {0};    printf ("Please enter a string: \ n");    scanf ("%[^\n]", str);//means non-' \ n '. This means that the input continues as long as no newline is encountered, and this statement ends when a newline character is encountered. By default, the end of a wrap statement execution is encountered, but the value of STR is just the value before the first space. However, when you press ENTER, SCANF executes and all of the contents including spaces are entered into Str.    gets (str);    int maxLength = 0, maxindex = 0;    int length = 0;    int i = 0;    while (str[i] = ' MaxL ') {        if (str[i]! = ') {            length++;        } else {            if (MaxLength < length) {                ength = length;                Maxindex = i-maxlength;            }            length = 0;        }        i++;    }    if (MaxLength < length) {        maxLength = length;        Maxindex = i-maxlength;    }    for (int j = Maxindex; J < Maxindex + MaxLength; j + +) {        printf ("%c", Str[j]);    }

Programming finds the longest word in a known string, assuming that the string contains only letters and spaces, separating the words with spaces.

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.