通過if語句實現for循環的提前結束


 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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM