zoukankan      html  css  js  c++  java
  • 避免数组或指针的下标越界,特别要当心发生“多 1”或者“少 1” 操作

    避免数组或指针的下标越界,特别要当心发生“多 1”或者“少 1” 操作。

     1 #include <iostream>
     2 #include <string.h>
     3 
     4 
     5 using namespace std;
     6 
     7 char string[80];
     8 char seps[]   = " ,	
    ";
     9 char *token;
    10 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    11 
    12 int main(int argc, char** argv) {
    13         //从键盘上输入两个语句
    14     for (int i=1;i<3;i++) {
    15         cout<<"Please input a sentence:"<<endl;
    16         //整行输入
    17         cin.getline(string,80);             
    18         cout<<"Tokens:"<<endl;
    19         //首次分离字符串
    20         token = strtok( string, seps );        
    21         while( token != NULL )              //结束分离判断
    22         {
    23             cout<<token<<endl;
    24             //下次分离字符串
    25             token = strtok( NULL, seps );   
    26         }
    27     }
    28 }
  • 相关阅读:
    13-Smell味道-调味料
    12-Juice饮料
    11-Snack小吃
    10-Meat肉类
    09-Fruit水果
    08-Vegetables蔬菜
    [svc]共享内存
    [sql]sql的select字符串切割
    [js] 渲染树构建、布局及绘制
    [js]变量提升-关于条件
  • 原文地址:https://www.cnblogs.com/borter/p/9413683.html
Copyright © 2011-2022 走看看