-
-
Save wbzyl/1459447 to your computer and use it in GitHub Desktop.
Program korzystający z plików.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
int c; | |
int nb = 0; /* liczba znaków odstępu */ | |
int nt = 0; /* liczba znaków tabulacji */ | |
int nl = 0; /* liczba znaków nowego wiersza */ | |
FILE *fin, *fout; | |
if ((fin = fopen(argv[1], "r")) == NULL) { | |
printf("Nie mogę otworzyć pliku do czytania '%s'\n", argv[1]); | |
return 1; | |
} | |
if ((fout = fopen(argv[2], "w")) == NULL) { | |
printf("Nie mogę otworzyć pliku do zapisu '%s'\n", argv[2]); | |
return 2; | |
} | |
while ((c = fgetc(fin)) != EOF) { | |
if (c == ' ') | |
nb++; | |
if (c == '\t') | |
nt++; | |
if (c == '\n') | |
nl++; | |
} | |
fprintf(fout, "\nliczba znaków odstępu = %d,\ntabulacji = %d,\nnowego wiersza = %d\n\n", nb, nt, nl); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment