Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAXLINEA 4095
- char linea[MAXLINEA+1];
- char * trozos[100];
- int TrocearCadena(char * cadena, char * trozos[]){
- int i = 1;
- if ((trozos[0]=strtok(cadena," \n\t"))==NULL){
- return 0;
- }
- while ((trozos[i]=strtok(NULL," \n\t"))!=NULL){
- i++;
- }
- return i;
- }
- void cmdAutores(int ntrozos, char * trozos[]){
- printf("Sergio Marcos - sergio.marcosv\n");
- }
- void cmdExit(int ntrozos, char * trozos[]){
- exit(0);
- }
- int main(){
- int ntrozos=0,i;
- while (1) {
- printf("@> ");
- if (fgets(linea, MAXLINEA, stdin) == NULL) {
- perror("fgets");
- exit(0);
- }
- ntrozos=TrocearCadena(linea,trozos);
- for (i = 0;i < ntrozos; i++) {
- if(strcmp(trozos[0],"autores")==0){
- cmdAutores(ntrozos,trozos);
- } else if (strcmp(trozos[0],"exit")==0){
- cmdExit(ntrozos,trozos);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment