本帖最后由 jackz007 于 2023-9-26 21:48 编辑 #include <stdio.h>
#include <string.h>
int main(void)
{
char command[1024]="cat<1.txt>2.txt>3.txt" , input_file[1024] , output_file[2][1024] , component[10][1024] ;
int i , k , m ;
for(i = m = 0 ; command[i] ;) {
for(k = 0 ; command[i] && command[i] != '<' && command[i] != '>' ; ) component[m][k ++] = command[i ++] ;
component[m][k] = '\0' ;
if(command[i]) {
component[m + 1][0] = command[i ++] ;
component[m + 1][1] = '\0' ;
m += 2 ;
}
}
m ++ ;
strcpy(input_file , component[2]) ;
strcpy(output_file[0] , component[4]) ;
strcpy(output_file[1] , component[6]) ;
printf(" input_file is : %s\n" , input_file) ;
printf("output_file is : %s , %s\n" , output_file[0] , output_file[1]) ;
}
编译、运行实况:D:\[exercise]\C>g++ -o x x.c
D:\[exercise]\C>x
input_file is : 1.txt
output_file is : 2.txt , 3.txt
D:\[exercise]\C>
|