Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <stdio.h>
- int getTxt(char *tab, int size)
- {
- if (tab == NULL || size <= 0)
- return -1;
- for (int i = 0; i < size; i++) {
- *(tab + i) = getchar();
- if (*(tab + i) == '\n') {
- *(tab + i) = '\0';
- break;
- }
- if (i + 1 == size)
- i--;
- }
- return 0;
- }
- int main(void)
- {
- printf("podaj nazwe pliku\n");
- FILE *plik, *copy;
- char a;
- char nazwa_zmiennej[31];
- getTxt(nazwa_zmiennej, 30);
- plik = fopen(nazwa_zmiennej, "r");
- if (plik == NULL) {
- printf("Couldn't open file");
- return 4;
- }
- printf("podaj 2 plik:\n");
- getTxt(nazwa_zmiennej, 30);
- copy = fopen(nazwa_zmiennej, "w");
- if (copy == NULL) {
- printf("Couldn't create file");
- fclose(plik);
- return 5;
- }
- a = getc(plik);
- while (a != EOF)
- {
- putc(a, copy);
- a = getc(plik);
- }
- printf("file copied");
- fclose(copy);
- fclose(plik);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement