Created
June 22, 2017 19:30
-
-
Save VTacius/aa287ddac46037c6cacf34ce9dca82a2 to your computer and use it in GitHub Desktop.
Eliminar un token de un cadena tokenizada con C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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