seergiomv

Práctica SO

Sep 23rd, 2020
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAXLINEA 4095
  6. char linea[MAXLINEA+1];
  7. char * trozos[100];
  8.  
  9. int TrocearCadena(char * cadena, char * trozos[]){
  10.     int i = 1;
  11.     if ((trozos[0]=strtok(cadena," \n\t"))==NULL){
  12.         return 0;
  13.     }
  14.     while ((trozos[i]=strtok(NULL," \n\t"))!=NULL){
  15.         i++;
  16.     }
  17.     return i;
  18. }
  19.  
  20. void cmdAutores(int ntrozos, char * trozos[]){
  21.     printf("Sergio Marcos - sergio.marcosv\n");
  22. }
  23.  
  24. void cmdExit(int ntrozos, char * trozos[]){
  25.     exit(0);
  26. }
  27.  
  28. int main(){
  29.     int ntrozos=0,i;
  30.     while (1) {
  31.         printf("@> ");
  32.         if (fgets(linea, MAXLINEA, stdin) == NULL) {
  33.             perror("fgets");
  34.             exit(0);
  35.         }
  36.         ntrozos=TrocearCadena(linea,trozos);
  37.         for (i = 0;i < ntrozos; i++) {
  38.             if(strcmp(trozos[0],"autores")==0){
  39.                 cmdAutores(ntrozos,trozos);
  40.             } else if (strcmp(trozos[0],"exit")==0){
  41.                 cmdExit(ntrozos,trozos);
  42.             }
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment