Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5.  
  6. int main(){
  7.  
  8.  
  9. char cmd[] = "iniciando string";
  10. char palavra1[] = "novaletras"; //inicializando string
  11. int i, j, tam;
  12. int contspace = 0, contc = 0; //contdores
  13. int tam_cmd[3];
  14.  
  15. while(1){
  16.  
  17. printf("\n \\Shellzinho: ");
  18. fgets(cmd, 101, stdin);
  19.  
  20. tam = strlen(cmd); //pegando tamanho da string
  21.  
  22. //verificando se tem espaços para delimitar as palavras
  23. for(i=0, j=0; i<tam; i++){
  24. if(isspace(cmd[i])){ //é espaço
  25. contspace++;
  26. tam_cmd[j] = i; //pegando a posição do espaço
  27. j++; //incrementando o vetor
  28. }
  29. else{
  30. contc++;
  31. }
  32. }
  33.  
  34. for(i=0; i<tam_cmd[0]; i++){
  35. palavra1[i] = cmd[i]; //pegando a primeira palavra
  36. }
  37.  
  38.  
  39. int rt1 = strcmp(palavra1, "criar");
  40. printf("\n\nRETORNO FUNCAO CRIAR = %d", rt1);
  41. if (rt1 == 0){
  42. printf("\nCmd mkdir");
  43. }
  44. else if ( strcmp(palavra1, "listar") ==0){
  45. printf("\nCmd ls");
  46. }
  47. else{
  48. printf("\nComando invalido\n\n\n --------------- \n");
  49. }
  50.  
  51.  
  52.  
  53. }
  54.  
  55. system("pause");
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement