PARSE.C
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:1k
- #include <string.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <rtos.h>
- #include <kconio.h>
- #undef word
- char *parse_arg( char * source, int word )
- {
- int i, len;
- int curword;
- int inspace;
- char *p, *start, ch;
- char *result;
- curword = 0;
- for ( p = source ; (ch = *p) != 0 ; p++ ) {
- if ( isspace( ch ) ) {
- if ( inspace ) {
- // still in space
- } else {
- // start of space
- inspace = 1;
- // was it the end of the special word
- if ( curword == word )
- break;
- }
- } else {
- if ( inspace ) {
- // start of new word
- curword ++;
- len = 1;
- start = p;
- inspace = 0;
- } else {
- // 2nd and other characters
- len++;
- }
- }
- }
- if ( curword == word ) {
- result = kcalloc( len + 1 , 1 );
- strncpy( result, start, len );
- result[ len ] = 0;
- } else
- result = NULL;
- return( result );
- }