Use the break statement to exit for loop - C Statement

C examples for Statement:break

Description

Use the break statement to exit for loop

Demo Code

#include <stdio.h>

char s[] = "This is a test string. It contains two sentences.";

int main( void )
{
   int count;/*from w w w .j a  v a 2 s  . c o  m*/

    printf("\nOriginal string: %s", s);

    for (count = 0; s[count]!='\0'; count++)
    {
        if (s[count] == '.')
        {
            s[count+1] = '\0';
            break;
        }
    }
    printf("\nModified string: %s\n", s);

    return 0;
}

Result


Related Tutorials