Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Separar por Tokens con strtok A.Villanueva
- * char *strtok(char *str, const char *delim)
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define FICHERO "cameConfig.txt"
- #define LONGITUD_MAX 64
- int main() {
- FILE *fptr;
- char * token;
- const char * sep = " ,.-!\t";//Separadores
- char linea[LONGITUD_MAX]; //Linea
- //Apertura del fichero
- if( (fptr = fopen(FICHERO,"r")) == NULL)//Abre el fichero en lectura
- {
- printf("Error! %s",FICHERO);
- exit(1);
- }
- while (fgets(linea, LONGITUD_MAX, fptr)){ //Lee linea
- token = strtok ( linea, sep );//Primer token
- while( token != NULL ) {//Recorro los tokens
- printf( " -> %s\n", token );
- token = strtok(NULL, sep);
- }
- }
- fclose(fptr);//Cierro fichero
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement