Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Przetwarzanie plikow tekstowych
- #include <stdio.h>
- #include <string.h>
- #include <windows.h>
- #include <conio.h>
- //Zmienne
- int a;
- void blad_wywyolania()
- {
- printf("\nBlad!\n\n");
- printf("Poprawny sposob wywolania: program.exe -argument\n");
- printf("Mozliwoc uzyskania pomocy poprzez wywyolanie argumentu -help\n");
- }
- void help()
- {
- printf("POMOC\n");
- for(int i=0 ; i<4 ; i++)
- {
- for(int j=0 ; j<4 ; j++)
- {
- printf("*");
- }
- printf("\n");
- }
- }
- int main(int argc , char **argv)
- {
- if(argc<2)
- {
- blad_wywyolania();
- }
- else if(argc==2 && (strcmp(argv[1],"-help")==0) || (strcmp(argv[1],"-?")==0))
- {
- help();
- }
- FILE * plik;
- long lSize;
- char * buffer;
- size_t result;
- plik = fopen ( "LSOF.txt" , "rb" );
- if (plik==NULL)
- {
- fputs ("File error",stderr);
- exit (1);
- }
- // obtain file size:
- fseek (plik , 0 , SEEK_END);
- lSize = ftell (plik);
- rewind (plik);
- // allocate memory to contain the whole file:
- buffer = (char*) malloc (sizeof(char)*lSize);
- if (buffer == NULL)
- {
- fputs ("Memory error",stderr);
- exit (2);
- }
- // copy the file into the buffer:
- result = fread (buffer,1,lSize,plik);
- if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
- /* the whole file is now loaded in the memory buffer. */
- for(int j=0 ; j<lSize ;j++)
- {
- fprintf(stdout , "%c", buffer[j]);
- }
- fclose (plik);
- free (buffer);
- return 0;
- }
Add Comment
Please, Sign In to add comment