格式如下的数据,是以逗号隔开的,如何拆分为一个一个的数据$GPGGA,010648.00,2307.594068,N,11321.993772,E,1,07,1.1,31.1,M,-5.2,M,,*48
$GPZDA,010648.00,05,04,2007,00,00*69
$GPGGA,010649.00,2307.594066,N,11321.993777,E,1,07,1.1,31.1,M,-5.2,M,,*42
$GPZDA,010649.00,05,04,2007,00,00*68
$GPGGA,010650.00,2307.594062,N,11321.993783,E,1,07,1.1,31.1,M,-5.2,M,,*45
$GPZDA,010650.00,05,04,2007,00,00*60
$GPGGA,010651.00,2307.594056,N,11321.993789,E,1,07,1.1,31.1,M,-5.2,M,,*49
例如:$GPGGA,010648.00,2307.594068,N,11321.993772,E,1,07,1.1,31.1,M,-5.2,M,,*48
拆分为 $GPGGA
       010648.00
       2307.594068
等等。void CAnalysisView::OnFileRead()
{
         CStdioFile   myFile; 
CString   oneLine; 
CString   linePart; if   (!myFile.Open( _T("gps.txt "),   CFile::modeRead   |   CFile::typeText)) 
{  
MessageBox( _T("打开文件错误 ")); 
return; 
}  while(myFile.ReadString(oneLine)) //这个循环是一行一行的读取文件,每一行读取后存入oneline 

MessageBox(oneLine);                  //想在此处建立一个循环,然后显示拆分后的每条数据。
while(循环条件该怎么写?)
                  {
                       sscanf("oneLine", "[^,]", linePart); 
     MessageBox(linePart);
                  }
}  
       

myFile.Close(); }

解决方案 »

  1.   

    // crt_strtok.c
    // compile with: /W3
    // In this program, a loop uses strtok
    // to print all the tokens (separated by commas
    // or blanks) in the string named "string".
    //
    #include <string.h>
    #include <stdio.h>char string[] = "A string\tof ,,tokens\nand some  more tokens";
    char seps[]   = " ,\t\n";
    char *token;int main( void )
    {
       printf( "Tokens:\n" );
     
       // Establish string and get the first token:
       token = strtok( string, seps ); // C4996
       // Note: strtok is deprecated; consider using strtok_s instead
       while( token != NULL )
       {
          // While there are tokens in "string"
          printf( " %s\n", token );      // Get next token: 
          token = strtok( NULL, seps ); // C4996
       }
    }
     
      

  2.   

    Tokens:
     A
     string
     of
     tokens
     and
     some
     more
     tokens
     
      

  3.   

    看起来要用到如下的方式:char   ch1[4],   ch2[4],   ch3[4], ch4[5]...;
    scanf( "分隔符1,分隔符2,分隔符3,分隔符4", "%s,%s,%s,%s ",ch1,   ch2,   ch3,   ch4);