This commit is contained in:
Bruno Rybársky 2024-04-22 16:04:50 +02:00
parent c631c7194c
commit a588e6d41b
3 changed files with 78 additions and 3 deletions

2
main.c

@ -1,5 +1,5 @@
#include "stringyreloaded.h"
int main() {
return stringyreloaded();
return volaco();
}

@ -43,3 +43,74 @@ int stringyreloaded() {
fclose(fw);
return 0;
}
int riadky() {
FILE *fp;
char stuff[25];
fp = fopen("s.txt", "w");
strcpy(stuff, "Toto je riadok");
for (int index = 1; index <= 10; index++) {
fprintf(fp, "%s, riadok číslo %d.\n", stuff, index);
}
fclose(fp);
}
int pridavanie() {
FILE *fp;
char stuff[35];
fp = fopen("s.txt", "a");
strcpy(stuff, "Toto je dalsi");
for (int index = 0; stuff[index]; index++) {
putc(stuff[index], fp);
putc('\n', fp);
}
fclose(fp);
}
int citanie() {
FILE *fp;
char c;
fp = fopen("s.txt", "r");
if (fp) {
do {
c = getc(fp);
if (c != EOF) {
putchar(c);
}
} while (c != EOF);
} else {
printf("s.txt neexistuje.");
}
return 0;
}
int volaco() {
FILE *fp;
char c;
int pocet = 1;
fp = fopen("s.txt", "r");
if (fp) {
printf("%d: ", pocet);
do {
c = getc(fp);
if (c == '\n') {
c = getc(fp);
if (!feof(fp)) {
printf("\n%d: ", ++pocet);
}
ungetc(c, fp);
} else {
if (!feof(fp)) {
putchar(c);
}
}
} while (!feof(fp));
fclose(fp);
} else {
printf("s.txt neexistuje");
}
}

@ -1 +1,5 @@
int stringyreloaded();
int citanie();
int riadky();
int pridavanie();
int volaco();