ejercicio de argchivos
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
ESTE ES UN ARCHIVO
|
||||||
|
DE PRUEBAS DONDE VAMOS A EVALUAR COMO
|
||||||
|
SE COPIA ESTE CORREO HORACIODRS@GMAIL.COM
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
char *src = "src-test.txt";
|
||||||
|
char *dst = "dst-test.txt";
|
||||||
|
|
||||||
|
if (argc == 3) {
|
||||||
|
src = strdup(argv[1]);
|
||||||
|
dst = strdup(argv[2]);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Argumentos invalidos.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *fpsrc, *fpdst;
|
||||||
|
|
||||||
|
fpsrc = fopen(src, "r");
|
||||||
|
|
||||||
|
if (fpsrc == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fpdst = fopen(dst, "w");
|
||||||
|
|
||||||
|
if (fpdst == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int c;
|
||||||
|
while ((c = fgetc(fpsrc)) && c != EOF) {
|
||||||
|
fputc(toupper(c), fpdst);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fpsrc);
|
||||||
|
fclose(fpdst);
|
||||||
|
|
||||||
|
printf("Archivo duplicado en mayusculas con exito en: %s\n", dst);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Este es un archivo
|
||||||
|
de pruebas donde vamos a evaluar como
|
||||||
|
se copia este correo horaciodrs@gmail.com
|
||||||
Binary file not shown.
@@ -0,0 +1,85 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc < 2) {
|
||||||
|
fprintf(stderr, "Argumentos invalidos\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *fname;
|
||||||
|
|
||||||
|
fname = strdup(argv[1]);
|
||||||
|
|
||||||
|
if (fname == NULL) {
|
||||||
|
perror("strdup");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *pfile = fopen(fname, "rb");
|
||||||
|
|
||||||
|
if (pfile == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
fclose(pfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *header = NULL;
|
||||||
|
|
||||||
|
header = malloc(sizeof(uint8_t) * 3);
|
||||||
|
|
||||||
|
printf("El sizeof de header es: %d\n", (int)sizeof(header));
|
||||||
|
|
||||||
|
if (fread(header, sizeof(uint8_t) * 2, 1, pfile) == 0) {
|
||||||
|
perror("fread");
|
||||||
|
fclose(pfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
header[3] = '\0';
|
||||||
|
|
||||||
|
int w, h, s;
|
||||||
|
|
||||||
|
if (fscanf(pfile, " %d %d %d", &w, &h, &s) != 3) {
|
||||||
|
fprintf(stderr, "Error leyendo las caracteristicas de la imagen.\n");
|
||||||
|
fclose(pfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "Header readed: %s\n", (unsigned char *)header);
|
||||||
|
fprintf(stdout,
|
||||||
|
"Las dimensiones son %dx%d pixeles y una escala maxima de color de "
|
||||||
|
"%d\n",
|
||||||
|
w, h, s);
|
||||||
|
|
||||||
|
// consumo un caracter mas y queda listo para leer los datos de los pixeles.
|
||||||
|
fgetc(pfile);
|
||||||
|
|
||||||
|
unsigned char *data = NULL;
|
||||||
|
unsigned long pixel_count = w * h;
|
||||||
|
|
||||||
|
data = malloc(sizeof(data) * pixel_count * 3);
|
||||||
|
|
||||||
|
if (data == NULL) {
|
||||||
|
perror("malloc");
|
||||||
|
fclose(pfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long readed =
|
||||||
|
fread(data, sizeof(unsigned char) * 3, pixel_count, pfile);
|
||||||
|
|
||||||
|
fprintf(stdout, "%zu pixeles leidos de %zu\n", readed, pixel_count);
|
||||||
|
|
||||||
|
if (readed != pixel_count) {
|
||||||
|
fprintf(stderr, "Error leyendo datos del archivo\n");
|
||||||
|
free(data);
|
||||||
|
fclose(pfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
fclose(pfile);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user