Skip to content

Instantly share code, notes, and snippets.

@VTacius
Created June 22, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VTacius/aa287ddac46037c6cacf34ce9dca82a2 to your computer and use it in GitHub Desktop.
Save VTacius/aa287ddac46037c6cacf34ce9dca82a2 to your computer and use it in GitHub Desktop.
Eliminar un token de un cadena tokenizada con C
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
// Esta es la cadena original. La idea es retirar el primer valor que aparezca
char line[] = "0 http://www.google.com.sv/ 10.168.3.5/10.168.3.5 - GET myip=10.168.3.1 myport=3128";
char delimitador[] = "\t ";
char resultado[strlen(line)];
char * ltr;
//sgLogNotice("Peticion original %s", line);
// Este es el primer token, ChannelID, que no nos interesa
ltr = strtok(line, delimitador);
// Con este, podemos limpiar el resultado de lo que sea con lo que se haya inicializado
ltr = strtok(NULL, delimitador);
strcpy(resultado, ltr);
// Y con este, hacemos los otros cuatro token, pero sobre todo, nos preparamos para más valores posibles
while ((ltr = strtok(NULL, delimitador)) != NULL){
strcat(resultado, " ");
strcat(resultado, ltr);
}
strcpy(line, resultado);
//sgLogNotice("Peticion adecuada %s", line);
printf("%s\n", line);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment