zoukankan      html  css  js  c++  java
  • sscanf,snprintf

    从一个字符串中读进与指定格式相符的数据.
    例子:
    #define COMPRESS_PET "%d,%d,%d,%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
    int nID = 0;
    int nRoleID = 0;
    int nSpeciesID = 0;
    int nGrade = 0;
    int nCharacter = 0;
    int nExp = 0;
    time_t nBirthday = 0;
    int nHp = 0;
    int nGrowRate = 0;
    int nHpLearn = 0;
    int nAttackLearn = 0;
    int nDefenseLearn = 0;
    int nSuperAttackLearn = 0;
    int nSuperDefenseLearn = 0;
    int nSpeedLearn = 0;
    int nActiveSkillOne = 0;
    int nActiveSkillOneCount = 0;
    int nActiveSkillTwo = 0;
    int nActiveSkillTwoCount = 0;
    int nActiveSkillThree = 0;
    int nActiveSkillThreeCount = 0;
    int nActiveSkillFour = 0;
    int nActiveSkillFourCount = 0;
    int nPassiveSkillOne = 0;
    int nPassiveSkillTwo = 0;
    int nPassiveSkillThree = 0;
    int nPassiveSkillFour = 0;
    int nPlace = 0;
    int nMaxHp = 0;
    int nAttack = 0;
    int nDefense = 0;
    int nSuperAttack = 0;
    int nSuperDefense = 0;
    int nSpeed = 0;
    sscanf((*iter).c_str(),COMPRESS_PET, &nID, &nRoleID, &nSpeciesID, &nGrade,
    &nCharacter, &nExp, &nBirthday, &nHp, &nGrowRate, &nHpLearn,
    &nAttackLearn, &nDefenseLearn, &nSuperAttackLearn, &nSuperDefenseLearn,
    &nSpeedLearn, &nActiveSkillOne, &nActiveSkillOneCount, &nActiveSkillTwo,
    &nActiveSkillTwoCount, &nActiveSkillThree, &nActiveSkillThreeCount,
    &nActiveSkillFour, &nActiveSkillFourCount, &nPassiveSkillOne,
    &nPassiveSkillTwo, &nPassiveSkillThree, &nPassiveSkillFour, &nPlace,
    &nMaxHp, &nAttack, &nDefense, &nSuperAttack, &nSuperDefense, &nSpeed);

    snprintf

    int snprintf(char *str, size_t size, const char *format, ...);
    将可变个参数(...)按照format格式化成字符串,然后将其复制到str中
    (1) 如果格式化后的字符串长度 < size,则将此字符串全部复制到str中,并给其后添加一个字符串结束符('\0');
    (2) 如果格式化后的字符串长度 >= size,则只将其中的(size-1)个字符复制到str中,并给其后添加一个字符串结束符('\0')
    函数返回值:若成功则返回欲写入的字符串长度,若出错则返回负值。
    例子:
    char *pBuffer = GetSQLBuffer();
    snprintf(pBuffer,GetSQLBufferSize() - 1, SQL_UPDATE_ROLE_PET, GetNum(), GetIDs().c_str(), GetDetails().c_str(),GetRoleID());
    char szSQL[1024] = {0};
    snprintf(szSQL, 1023, SQL_QUERY_ROLE_PET_BINARY, GetRoleID());

  • 相关阅读:
    如何创建一个WebService
    javascript调用WebService Hello World
    音频处理介绍(Linux手机)
    Android开机画面大整容
    android 源代码结构
    移植 android, touch screen 不能正常工作的问题
    为 Linux 应用程序编写 DLL
    6410 声卡wm9713 驱动分析
    android bootload源码网址
    fprintf 控制台代码,可以控制光标等,控制台显示时间源码
  • 原文地址:https://www.cnblogs.com/byfei/p/14104745.html
Copyright © 2011-2022 走看看