All pastes #987765 Raw Edit

pecucha

public c v1 · immutable
#987765 ·published 2008-04-16 22:45 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <signal.h>#include <sys/types.h>#include <sys/wait.h>#define MAX 1000int gettexto(char *buf, int bufsize){       int nchars;       nchars=read(STDIN_FILENO, buf, bufsize);       return nchars;}void parsestring(char* input, char* output[]){  int i = -1,    contador = 0, cont = 0;  char palabra[100];  char* ptr = palabra;  do    {      ++i;      if (!isblank(input[i]) && input[i] != '\0')        {          ptr[contador] = input[i];          contador++;        }      else        {          if(contador != 0)            {              ptr[contador] = '\0';              output[cont] = (char*)malloc((contador+1)*sizeof(char));              strcpy(output[cont], palabra);              contador = 0;              cont++;            }        }    } while (input[i] != '\0');  output[cont] = "0";}int main(int argc,char *argv[]){  int contador =0;  char linea[MAX];  gettexto(linea,MAX);  parsestring(linea,argv);  for(contador; argv[contador] != "0"; contador++)     {       printf("%s\n", argv[contador]);     }  return 0;}