Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void copyfile(const char* source, const char* dest, int buffersize)
- {
- FILE* pSource = fopen(source, "rb");
- FILE* pDest = fopen(dest, "wb");
- if(pSource && pDest)
- {
- char* buffer = (char*)malloc(buffersize*sizeof(char));
- fread(buffer, sizeof(char) ,buffersize,pSource);
- fwrite(buffer,sizeof(char),buffersize,pDest);
- }
- fclose(pSource);
- fclose(pDest);
- }
- int main ( void )
- {
- /* zadanie 4
- copyfile("source.txt","dest.txt",1000);
- */
- /* zadanie 5 */
- FILE* pSource = fopen("plik.txt", "rb");
- FILE* pDest = fopen("nowyplik.txt", "wb");
- if(pSource && pDest)
- {
- char bufferPoczatek[5];
- char bufferSrodek[5];
- char bufferKoniec[5];
- fseek(pSource,0,SEEK_SET);
- fread(bufferPoczatek,1,5,pSource);
- fwrite(bufferPoczatek,1,5,pDest);
- fseek(pSource,0,SEEK_END);
- int srodek = ftell(pSource) / 2;
- fseek(pSource, srodek, SEEK_SET);
- fread(bufferSrodek,1,5,pSource);
- fwrite(bufferSrodek,1,5,pDest);
- fseek(pSource,-5,SEEK_END);
- fread(bufferKoniec,1,5,pSource);
- fwrite(bufferKoniec,1,5,pDest);
- }
- fclose(pSource);
- fclose(pDest);
- /* zadanie 1
- FILE* pFile = fopen("tekst.txt", "r");
- if(pFile)
- {
- while(feof(pFile) == 0)
- {
- char c[100];
- fgets(c,100,pFile);
- printf("%s",c);
- }
- }
- fclose(pFile);
- */
- /* zadanie 2
- int ilosc_znakow = 0;
- FILE* pFile = fopen("tekst.txt", "r");
- if(pFile)
- {
- while(feof(pFile) == 0)
- {
- char c[100];
- fgets(c,100,pFile);
- ilosc_znakow += strlen(c);
- // printf("%s",c);
- }
- printf("%d",ilosc_znakow);
- }
- fclose(pFile);
- */
- /* zadanie 3
- FILE* pFile1 = fopen("tekst1.txt", "r");
- FILE* pFile2 = fopen("tekst2.txt", "r");
- if(pFile1 && pFile2)
- {
- while(1)
- {
- char c1[100];
- char c2[100];
- fgets(c1,100,pFile1);
- fgets(c2,100,pFile2);
- int result = strcmp(c1,c2);
- if(result != 0)
- {
- break;
- }
- else
- {
- printf("%s",c1);
- }
- }
- }
- fclose(pFile1);
- fclose(pFile2);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement