我用一个文本存储下面一段程序。现在我想把它读出来,并一个词截成一个字符串,例如“main”, “(” ,“)”,“int”,“ = ”这样。但是我现在总是不能过滤掉换行和空格,总是把一个换行符截成一个字符串。求解如何避免main()
{
int a = 5,b = 2,c = 3,max;
if(a>b)
{
if(a>c)
max = a;
else
max = c;
}
else if(b > c)
max = b;
else max = c;  
}CString

解决方案 »

  1.   

    Example/* STRTOK.C: 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;void main( void )
    {
       printf( "%s\n\nTokens:\n", string );
       /* Establish string and get the first token: */
       token = strtok( string, seps );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, seps );
       }
    }
    OutputA string   of ,,tokens
    and some  more tokensTokens:
     A
     string
     of
     tokens
     and
     some
     more
     tokens
      

  2.   

    CString::TrimLeft
    CString::TrimRight