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 }