Saludos a todos!
estaba leyendo sobre punteros , y me dio por crear 3 funciones(snipets) , para tres de las funciones mas conocidas
de la libreia "strings.h" , usanda nada mas que punteros............
Las Funciones como sabran son mutiplataforma , y vitualmente no dependen de ninguna
libreria.................

Les dejo las funciones por separado , y un code de Ejemplo ....

Semejante a "strcat" de la LIbreria "strings.h"

Código: Seleccionar todo

char* _strcat(char* string , char* hString)
{
  char *pS = string;
  char *hS = hString;

 while(*hS != '\0')
 {
     while(*pS != '\0')
     {
        *pS++;
     }
 *pS = *hS++;
 }
return pS;
}
Semejante a "strlen" de la LIbreria "strings.h"

Código: Seleccionar todo

int _strlen(char *str) 
{
   int i=0;
   char* p = str; 

   while(*p)
   {
     i++; 
    *p++; 
   }
return i; //Retornamos I
}
Semejante a "strcpy" de la LIbreria "strings.h"

Código: Seleccionar todo

char *_strcpy(char *ztr , char *new) //strcpy alternativo
{
 char *s = ztr;
 char *n = new;

  while(*n)
  {
    *s = *n++;
    *s++;
  }
 return ztr;
}
Code de Ejemplo:

Código: Seleccionar todo

#include <stdio.h>

/*
Coder : ØnLy
Fecha : 08/01/2011
Lenguaje : "C"
Dedicate : http://www.indetectables.net
Blog : http://onlydevelopments.blogspot.com/
PD : Compilado en GNU/Linux-Dist.Ubuntu           
*/

//Prototipos de las Funciones....
int  _strlen(char*);
char *_strcpy(char *,char*); 
char *_strcat(char*,char*);

int main() //Funcion Principal!
{
 char buff[256]= {'\0'};
 char buffer[256] = {'\0'};
 char xD[10]=">>>>xD";
   
 printf("Ingrese Un Texto : "); //Pedimos Que se Ingrese UN String
 scanf("%s" , &buff); //Lo leemos de L	 pantalla!
 
 printf("Longitud de la Cadena : %d \n" , _strlen(buff) ); //LA funcion retorna Su Longitud!

 _strcpy(buffer,buff);
 printf("Cadena Copiada : %s \n" , buffer); //Copiamos la cadna apuntada por "buff" a "buffer"..

 _strcat(buffer,xD);
 printf("Cadena Concatenada : %s \n" , buffer); //Concatenamos la cadena apuntada a "buffer" con "xD";

return 0;
}

char* _strcat(char* string , char* hString)
{
  char *pS = string;
  char *hS = hString;

 while(*hS != '\0')
 {
       while(*pS != '\0')
       {
         *pS++;
       }
  *pS = *hS++;
}
return pS;
}

int _strlen(char *str) 
{
   int i=0;
   char* p = str;  

   while(*p)
   {
     i++; 
    *p++; 
   }
return i;
}

char *_strcpy(char *ztr , char *new) //strcpy alternativo
{
 char *s = ztr;
 char *n = new;

 while(*n)
 {
   *s = *n++;
   *s++;
 }
return ztr;
}
A Muchos no les gusta manejar punteros en este Lenguaje , pero este es uno de los fuertes de "C" y "C++" , mejor
aprender a sacarles provecho!!!

Es solo un ejemplo , son funciones sencilllas y buenas para entender la naturalesa
de los punteros..

Saludos!
obey escribió:Pues si tuviese mas edad todavia pero esqe perder la virginidad con tu profesora de informatica y que ademas tenga 50....
.
este es mi strcpy()

Código: Seleccionar todo


void strcpy(char* str_dest,char* str_src)
{
    while( *str_dest++=*str_src++ );
}

uso simple:

Código: Seleccionar todo


#include <stdio.h>
void strcpy(char* str_dest,char* str_src);
int main()
{
    char arr_s[20]= "Hola\0";
    char arr_d[20];
    strcpy(&arr_d[0],&arr_s[0]);
    printf("%s",arr_d);
    getchar();
}
void strcpy(char* str_dest,char* str_src)
{
    while( *str_dest++=*str_src++ );
}

Temibles Lunas!¡.
.
Web: http://infrangelux.sytes.net/
ScanX: http://ScanX.sytes.net/
FileX: http://FileX.sytes.net/
Blog: http://BlogX.sytes.net/

Imagen


The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi religion
Responder

Volver a “Fuentes”