files
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
Hola, mundo
|
||||||
|
C es genial
|
||||||
|
Fin
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int count_chars(char *rline);
|
||||||
|
void fix_path(char *rpath);
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char file_path[128];
|
||||||
|
int char_count = 0, lines_count = 0;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
printf("Path:");
|
||||||
|
if (fgets(file_path, 128, stdin) == NULL) {
|
||||||
|
perror("fgets");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("\nLeyendo archivo: %s", file_path);
|
||||||
|
|
||||||
|
fix_path(file_path);
|
||||||
|
|
||||||
|
fp = fopen(file_path, "r");
|
||||||
|
|
||||||
|
if (fp == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char lbuffer[256];
|
||||||
|
|
||||||
|
while ((fgets(lbuffer, 256, fp)) != NULL) {
|
||||||
|
char_count += count_chars(lbuffer);
|
||||||
|
lines_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Caracteres: %d\n", char_count);
|
||||||
|
printf("Lineas: %d\n", lines_count);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count_chars(char *rline) { return strlen(rline) - 1; }
|
||||||
|
|
||||||
|
void fix_path(char *rpath) {
|
||||||
|
for (int i = 0; i < 128; i++) {
|
||||||
|
if (rpath[i] == '\n') {
|
||||||
|
rpath[i] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user