Writing /var/lib/dokuwiki/data/meta/teaching/ie0117/actividad_funciones_recursion.meta failed
teaching:ie0117:actividad_funciones_recursion
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| teaching:ie0117:actividad_funciones_recursion [2016/06/14 01:28] – [Instrucciones] admin | teaching:ie0117:actividad_funciones_recursion [2022/09/20 00:08] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== Funciones, recursión, entrada, salida y funciones de sistema ====== |
| ===== Funciones que podrían ser utilizadas en esta actividad ===== | ===== Funciones que podrían ser utilizadas en esta actividad ===== | ||
| Line 7: | Line 7: | ||
| ===== Instrucciones ===== | ===== Instrucciones ===== | ||
| + | |||
| + | ==== Programa Examinador de directorios ==== | ||
| Line 31: | Line 33: | ||
| * Modifique el programa anterior para que lea el contenido de root_dir/ | * Modifique el programa anterior para que lea el contenido de root_dir/ | ||
| * Utilizando los programas anteriores y recursión, construya un programa que examine todo el árbol de archivos de arriba y copie la lista de archivos (con su directorio) de todos los archivos terminados en .txt en pantalla y en el archivo " | * Utilizando los programas anteriores y recursión, construya un programa que examine todo el árbol de archivos de arriba y copie la lista de archivos (con su directorio) de todos los archivos terminados en .txt en pantalla y en el archivo " | ||
| + | |||
| + | ==== Algunas funciones de ayuda ==== | ||
| + | |||
| + | Estas funciones pueden contener errores y estar incompletas (no se chequean errores). Usted es responsable de corregirlas o completarlas. | ||
| + | |||
| + | int get_len(char *data) { | ||
| + | int len=0; | ||
| + | while(data[len]!=' | ||
| + | len++; | ||
| + | } | ||
| + | return(len); | ||
| + | } | ||
| + | |||
| + | |||
| + | char * get_dir(char *filename) { | ||
| + | char *output; | ||
| + | output=calloc(256, | ||
| + | int last_dir_pos=0; | ||
| + | int i; | ||
| + | for (i=0; i<256; i++) { | ||
| + | if (filename[i]=='/' | ||
| + | last_dir_pos=i; | ||
| + | } else { | ||
| + | if (filename[i]==' | ||
| + | break; | ||
| + | } else { | ||
| + | if (filename[i]==' | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | if ((i==256) || (last_dir_pos==0)) { | ||
| + | output[0]=' | ||
| + | } else { | ||
| + | for (i=0; i< | ||
| + | output[i]=filename[i]; | ||
| + | } | ||
| + | } | ||
| + | return(output); | ||
| + | } | ||
| + | |||
| + | void mystrcpy(char *dataout, char *datain) { | ||
| + | int i=0; | ||
| + | char c; | ||
| + | while ((c=datain[i])!=' | ||
| + | dataout[i]=c; | ||
| + | i++; | ||
| + | } | ||
| + | dataout[i]=' | ||
| + | dataout[++i]=' | ||
| + | } | ||
| + | |||
| + | char *grow_str(char *old, char sep, char *new) { | ||
| + | int old_total_size=get_len(old); | ||
| + | printf(" | ||
| + | char *output=realloc(old, | ||
| + | output[old_total_size]=sep; | ||
| + | mystrcpy(output+old_total_size+1, | ||
| + | output[old_total_size+get_len(new)+1]=' | ||
| + | return(output); | ||
| + | } | ||
| + | |||
| + | bool is_txt(char *filename) { | ||
| + | int len; | ||
| + | len=get_len(filename); | ||
| + | if ((filename[len-1]==' | ||
| + | return(true); | ||
| + | } else { | ||
| + | return(false); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | bool is_dir(char *filename) { | ||
| + | struct stat mystat; | ||
| + | printf(" | ||
| + | if (stat(filename, | ||
| + | printf(" | ||
| + | printf(" | ||
| + | exit(0); | ||
| + | } | ||
| + | mode_t mymode; | ||
| + | mymode=mystat.st_mode; | ||
| + | if (S_ISDIR(mymode)) { | ||
| + | return(true); | ||
| + | } else { | ||
| + | return(false); | ||
| + | } | ||
| + | } | ||
| + | |||
teaching/ie0117/actividad_funciones_recursion.1465867716.txt.gz · Last modified: 2022/09/20 00:08 (external edit)