-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunix2dos.c
64 lines (52 loc) · 1.24 KB
/
unix2dos.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
int main(int argc, char *argv[]) {
FILE *entrada;
FILE *salida;
char caracter;
bool entradaEstandar = true;
bool salidaEstandar = true;
int i;
for (i = 0; i < argc; i++){
if ((strcmp(argv[i], "-i") == 0)){
if (argc > i+1){
if (strcmp(argv[i+1], "-") != 0){
entrada = fopen(argv[i+1], "r");
entradaEstandar = false;
}
}
}
if ((strcmp(argv[i], "-o") == 0)){
if (argc > i+1){
if (strcmp(argv[i+1], "-") != 0){
salida = fopen(argv[i+1], "w");
salidaEstandar = false;
}
}
}
}
if(entradaEstandar){
entrada = stdin;
}
if(salidaEstandar){
salida = stdout;
}
if (entrada == NULL){
fprintf(stderr,"Error al cargar el archivo");
return 0;
}
while((caracter = fgetc(entrada)) != EOF)
{
if(caracter == '\n'){
fputc('\r',salida);
fputc('\n',salida);
}else{
fputc(caracter,salida);
}
}
fclose(entrada);
fclose(salida);
return 0;
}