elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  [APORTE] Lector de Ficheros
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] Lector de Ficheros  (Leído 1,470 veces)
Namida

Desconectado Desconectado

Mensajes: 18



Ver Perfil
[APORTE] Lector de Ficheros
« en: 17 Mayo 2010, 19:27 pm »

¡Muy Buenas!

Aqui os dejo mi pequeño aporte. Se trata de un código que se encarga de cargar 'palabras' de un fichero en una lista simple para que después pueda ser leida e interpretada por otro código. Espero os resulte útil, y cualquier error, duda o crítica que me comuniqueis será bienvenida. De antemano ¡Gracias!  :D

Nombre Original del Archivo: fword.h
Código:
#ifndef _FWORD_
#define _FWORD_
#endif

#ifndef _FSTREAM_
#include <fstream>
#endif

#ifndef NULL
#define NULL 0
#endif

struct L_word{
int wordc;
char* wordv;
struct L_word* next;
};
void L_word_add(struct L_word *&p,char* argv,int argc){
struct L_word* new_node;
struct L_word* aux_node;
new_node=new struct L_word;
new_node->next=NULL;
new_node->wordc=argc;
new_node->wordv=argv;
if(p==NULL){
p=new_node;
}else{
aux_node=p;
while(aux_node->next!=NULL){
aux_node=aux_node->next;
}
aux_node->next=new_node;
}
};
struct L_word* L_fword(char* file_name){
struct L_word* pointer=NULL;
fstream file(file_name,ios::in|ios::binary);
if(file.good()){
bool w=false;
while(!w){
int argc;
char aux;

do{
argc=0;
do{
file.read(reinterpret_cast<char*>(&aux),sizeof(char));
w=file.eof();
argc++;
}while((aux!=' ')&&(aux!='\n')&&(aux!='\t')&&(aux!='\0')&&(aux!=char(13))&&(!w));
}while((argc<2)&&(!w));

char* argv;
argv=new char[argc];

if(w){
file.clear();
file.seekg(-argc+1,ios::cur);
file.read(reinterpret_cast<char*>(argv),sizeof(char)*(argc-2));
file.read(reinterpret_cast<char*>(&aux),sizeof(char));
argv[argc-2]=aux;
}else{
file.seekg(-argc,ios::cur);
file.read(reinterpret_cast<char*>(argv),sizeof(char)*(argc-1));
}
argv[argc-1]='\0';
L_word_add(pointer,argv,argc);
file.seekg(1,ios::cur);
}
}
file.close();
return pointer;
};

Microsoft Visual Studio 2008


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Aporte] Cifrado de ficheros txt
Programación C/C++
MiBean Projects 1 1,671 Último mensaje 26 Junio 2014, 19:07 pm
por Eternal Idol
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines