Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- int main(){
- char cmd[] = "iniciando string";
- char palavra1[] = "novaletras"; //inicializando string
- int i, j, tam;
- int contspace = 0, contc = 0; //contdores
- int tam_cmd[3];
- while(1){
- printf("\n \\Shellzinho: ");
- fgets(cmd, 101, stdin);
- tam = strlen(cmd); //pegando tamanho da string
- //verificando se tem espaços para delimitar as palavras
- for(i=0, j=0; i<tam; i++){
- if(isspace(cmd[i])){ //é espaço
- contspace++;
- tam_cmd[j] = i; //pegando a posição do espaço
- j++; //incrementando o vetor
- }
- else{
- contc++;
- }
- }
- for(i=0; i<tam_cmd[0]; i++){
- palavra1[i] = cmd[i]; //pegando a primeira palavra
- }
- int rt1 = strcmp(palavra1, "criar");
- printf("\n\nRETORNO FUNCAO CRIAR = %d", rt1);
- if (rt1 == 0){
- printf("\nCmd mkdir");
- }
- else if ( strcmp(palavra1, "listar") ==0){
- printf("\nCmd ls");
- }
- else{
- printf("\nComando invalido\n\n\n --------------- \n");
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement