Estamos jodidos... esto va de mal en peor. Al final sí que van a privatizar tanto internet que sólo unos pocos lo tendrán...
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
/* char **split(char *string, char *sep);
Coded by Binary_Death on 30/6/2011
*/
#include <stdlib.h>
#include <stdio.h>
typedef struct {
char **substring_ptr;
int number_of_substrings;
} split_struct;
split_struct* split(char*,char*);
int _strlen(char*);
int _cmp(char*,char*,int);
int main() {
split_struct *str;
str = split("STRING1#DLM#STRING2#DLM#STRING3","#DLM#");
for(int y=0;y<str->number_of_substrings;y++)
{printf("%s\n", str->substring_ptr[y]);}
getchar();
return 0;
}
split_struct *split(char *string,char *sep) {
split_struct *retvalue;
retvalue = (split_struct*)malloc(sizeof(split_struct));
int str_len=_strlen(string);
int sep_len=_strlen(sep);
int ptr_block=0, chr=0, bool_end=0;
char **buffer = (char**)malloc(sizeof(char*));
*buffer = (char*)malloc(sizeof(char*));**buffer=0;
char *tok = (char*)malloc(sep_len*sizeof(char));
for(int z=0;z<str_len;z++) {
for(int n=0;n<sep_len&&!bool_end;n++)
tok[n]=(z+n<str_len)?string[z+n]:bool_end=1;
if(_cmp(tok,sep,sep_len)||bool_end) {
buffer[ptr_block][chr++] = string[z];
buffer[ptr_block] = (char*)realloc(buffer[ptr_block],chr*sizeof(char*));
buffer[ptr_block][chr] = 0;
} else {
buffer = (char**)realloc(buffer,(++ptr_block+1)*sizeof(char*));
buffer[ptr_block] = (char*)malloc(sizeof(char*));**(buffer+ptr_block)=0;
chr=0;z+=sep_len-1;
}
}
free(tok);
retvalue->substring_ptr = buffer;
retvalue->number_of_substrings = ptr_block+1;
return retvalue;
}
int _strlen(char *pstr) {
int i=0;
while(*(pstr++)!='\0') i++;
return i;
}
int _cmp(char *fstr,char *sstr, int len) {
int bytes=0;
while(bytes++<len) if(*(fstr++)!=*(sstr++)) return 1;
return 0;
}
/* char **split(char *string, char *sep);
Coded by Binary_Death on 30/6/2011
*/
#include <stdlib.h>
#include <stdio.h>
char **split(char*,char*);
int _strlen(char*);
int _cmp(char*,char*,int);
int main() {
char **array = split("STRING1#DLM#STRING2#DLM#STRING3","#DLM#");
for(int y=0;y<3;y++) printf("%s\n", array[y]);
getchar();
return 0;
}
char **split(char *string,char *sep) {
int str_len=_strlen(string);
int sep_len=_strlen(sep);
int ptr_block=0, chr=0, bool_end=0;
char **buffer = (char**)malloc(sizeof(char*));
*buffer = (char*)malloc(sizeof(char*));**buffer=0;
char *tok = (char*)malloc(sep_len*sizeof(char));
for(int z=0;z<str_len;z++) {
for(int n=0;n<sep_len&&!bool_end;n++)
{(str_len-(z+1)>=sep_len)?tok[n]=string[z+n]:bool_end=1;}
if(_cmp(tok,sep,sep_len)||bool_end) {
buffer[ptr_block][chr++] = string[z];
buffer[ptr_block] = (char*)realloc(buffer[ptr_block],chr*sizeof(char*));
buffer[ptr_block][chr] = 0;
} else {
buffer = (char**)realloc(buffer,(++ptr_block+1)*sizeof(char*));
buffer[ptr_block] = (char*)malloc(sizeof(char*));
chr=0;z+=sep_len-1;
}
}
free(tok);
return buffer;
}
int _strlen(char *pstr) {
int i=0;
while(*(pstr++)!='\0') i++;
return i;
}
int _cmp(char *fstr,char *sstr, int len) {
int bytes=0;
while(bytes++<len) if(*(fstr++)!=*(sstr++)) return 1;
return 0;
}
;;;;;;;;;;;;;;;;;
;String Reverse ;
;By Binary_Death;
;;;;;;;;;;;;;;;;;
segment Data
msg1 db 'Cadena a invertir: $'
msg2 db 'Cadena invertida: $'
string times 256 db ' '
char db ' $'
clf db 10,13,10,13,'$'
segment Stack stack
resb 256
StackEnd:
segment Code
..start:
mov ax, Stack
mov ss, ax
mov sp, StackEnd
mov ax, Data
mov ds, ax
mov ah,9h
mov dx,msg1
int 21h
xor bx,bx
SaveStr:
xor ah,ah
int 16h
cmp al,0Dh
je ShowStr
mov [string+bx],al
mov [char],al
mov dx,char
mov ah,9
int 21h
cmp bx,00FFh
je ShowStr
inc bx
jmp SaveStr
ShowStr:
mov ah,9h
mov dx,clf
int 21h
mov dx,msg2
int 21h
dec bx
LoopPos:
mov al,[string+bx]
mov [char],al
mov ah,9h
mov dx,char
int 21h
cmp bx,00h
je Exit
dec bx
jmp LoopPos
Exit:
xor ah,ah
int 16h
mov ah,4ch
int 21h
;;;;;;;;;;;;;;;;;
;;StrRev 16 bit;;
;; NASM ;;
;;Binary_Death ;;
;;;;;;;;;;;;;;;;;
segment data
MSG1 DB 'Cadena a Invertir: $'
MSG2 DB 'Cadena Invertida: $'
CRNL DB 10,13,'$'
BKSC DB 8,'$'
CHR1 DB ' $'
segment stck stack
resb 256
SpOffset:
segment code
..start:
;Asumimos segmentos
mov ax,data
mov ds,ax ;DS=Data
mov es,ax ;ES=Data
mov ax,stck
mov ss,ax ;SS=Stck
mov sp,SpOffset ;SP=Offset(SpOffset)
mov ah,9h
mov dx,MSG1
int 21h ;Mostramos MSG1 en pantalla
mov dx,0FFh
xor cx,cx
PushLoop:
xor ah,ah
int 16h ;Pedimos carácter por teclado
cmp al,9h ;Si CHR=BS
jz BackSpace ;jmp BackSpace
cmp al,0Dh ;Si chr=\CR
jz ShowStr ;jmp ShowStr
push ax ;Empujamos AH+AL(=00+Chr) a stack
mov [CHR1],al ;Guardamos carácter en memoria
mov ah,9h
mov dx,CHR1
int 21h ;Mostramos el carácter guardado
inc cx ;Incrementamos CX
dec dx ;Decrementamos DX
jnz PushLoop ;Si CX!=0 jmp PushLoop
ShowStr:
mov ah,9h
mov dx,CRNL ;Salto de línea
int 21h ;Efectuamos
PopLoop:
pop ax ;Recuperamos último CHR
mov [CHR1],al ;Lo guardamos en CHR1
mov ah,9h
mov dx,CHR1
int 21h ;Lo mostramos en pantalla
loop PopLoop ;Si CX!=0 jmp PopLoop
Exit:
xor ah,ah
int 16h ;Hacemos pausa
mov ah,4ch
int 21h ;Devolvemos control al OS
BackSpace:
mov ah,9h
mov dx,BKSC
int 21h
jmp PushLoop
Citar
Otros registros fundamentales, que deben configurarse al iniciar la ejecución de cualquier programa, son BP (Base Pointer) y SP (Stack Pointer). Ambos trabajan conjuntamente con el registro de segmento SS para definir la dirección base de la pila, que estaría en la dirección CS:BP, y la posición actual en la que están insertándose o recuperándose datos, que sería CS:SP. La pila es una estructura que crece en orden inverso, es decir, en principio CS contendrá el valor del final de pila, mientras que SP irá reduciéndose a medida que se inserten datos o incrementándose al extraerlos.