|
发表于 2013-1-13 02:53:02
|
显示全部楼层
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- char *str_input = NULL;
- char *handle_loc = NULL;
- char first_char;
- int i, num, len;
-
- printf( "please input the probable max number of your str: ___\b\b\b" ); //input info
- scanf( "%d", &num );
-
- if( num < 0 )
- {
- perror( "the num can't be negative!\n" );
- exit( EXIT_FAILURE );
- }
-
- str_input = (char *)malloc( num * sizeof(char) + 1 );
- if( str_input == NULL )
- {
- perror( "No adequate space!\n" );
- exit( EXIT_FAILURE );
- }
-
- memset( str_input, 0, num * sizeof(char) + 1 );
-
- printf( "please input the string: " );
-
- while( getchar() != '\n' ); //input str
- fgets( str_input, num, stdin );
-
-
- len = strlen(str_input); //the arithmetic
- for( first_char = str_input[1], i = 1; i <= len - 3; i += 2 )
- {
- str_input[i] = str_input[i+2];
- }
-
- str_input[i] = first_char;
-
- printf( "the str after handling is: %s\n", str_input );
-
- }
复制代码 好久没写代码了,将就看吧。 |
|