51 lines
968 B
C
51 lines
968 B
C
#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;
|
|
}
|
|
}
|
|
}
|