Skip to content

Instantly share code, notes, and snippets.

@wbzyl
Created December 11, 2011 08:56
Show Gist options
  • Save wbzyl/1459447 to your computer and use it in GitHub Desktop.
Save wbzyl/1459447 to your computer and use it in GitHub Desktop.
Program korzystający z plików.
#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