1 /*************************************************************************
2 > File Name: mybreaking.c
3 > Author: Mr.Yang
4 > Purpose:重写提前结束for循环
5 > Created Time: 2017年05月19日 星期五 13时17分56秒
6 ************************************************************************/
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 char s[]="this is a test string.it contains two sentences.";
12
13 int main(void)
14 {
15 printf("%s\n",s);//记住打印字符串可以直接通过指针打印,同时记住不要括号号的数组是数组的指针,指向数组的第一个字符
16
17 int i = 0;
18 for(i = 0;s[i] != '\0';i++)//实现for循环的提前结束,实现方式就是让for循环的条件通过if语句提前满足
19 {
20 if(s[i] == '.')
21 {
22 s[i+1] = '\0';
23 break;
24 }
25 }
26 printf("%s\n",s);
27 return 0;
28 }