怎样将"your score 70 and passed"中的"70"赋给一个int型变量?

解决方案 »

  1.   

    char strIn[]="your score 70 and passed";
    int nOut;
    sscanf(strIn,"your score %d and passed",&nOut);
      

  2.   

    int n = -1;
    const char* p = "your score 70 and passed";
    char buf[100];sscanf(p,"%s %s %d", buf,buf,&n);KAO,还不给分?
      

  3.   

    sscanf(strIn,"your score %d and passed",&nOut);
      

  4.   

    谢谢,但我还是不太理解,假设有"2003-4-2   18:39:58  70 80  hehe"怎样将"2003-4-2” 中的“4”赋给int变量?再次感谢!
      

  5.   

    char str[]="2003-4-2   18:39:58  70 80  hehe";
    int n;
    sscanf(str,"2003-%d-2   18:39:58  70 80  hehe",&n);
      

  6.   

    hehe终于明白了,给分!!!谢谢大家!