Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. //Przetwarzanie plikow tekstowych
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. #include <conio.h>
  6.  
  7. //Zmienne
  8. int a;
  9.  
  10.  
  11. void blad_wywyolania()
  12. {
  13. printf("\nBlad!\n\n");
  14. printf("Poprawny sposob wywolania: program.exe -argument\n");
  15. printf("Mozliwoc uzyskania pomocy poprzez wywyolanie argumentu -help\n");
  16. }
  17.  
  18. void help()
  19. {
  20. printf("POMOC\n");
  21. for(int i=0 ; i<4 ; i++)
  22. {
  23. for(int j=0 ; j<4 ; j++)
  24. {
  25. printf("*");
  26. }
  27. printf("\n");
  28. }
  29. }
  30.  
  31. int main(int argc , char **argv)
  32. {
  33.  
  34. if(argc<2)
  35. {
  36. blad_wywyolania();
  37. }
  38. else if(argc==2 && (strcmp(argv[1],"-help")==0) || (strcmp(argv[1],"-?")==0))
  39. {
  40. help();
  41. }
  42.  
  43. FILE * plik;
  44. long lSize;
  45. char * buffer;
  46. size_t result;
  47.  
  48. plik = fopen ( "LSOF.txt" , "rb" );
  49. if (plik==NULL)
  50. {
  51. fputs ("File error",stderr);
  52. exit (1);
  53. }
  54.  
  55. // obtain file size:
  56. fseek (plik , 0 , SEEK_END);
  57. lSize = ftell (plik);
  58. rewind (plik);
  59.  
  60. // allocate memory to contain the whole file:
  61. buffer = (char*) malloc (sizeof(char)*lSize);
  62. if (buffer == NULL)
  63. {
  64. fputs ("Memory error",stderr);
  65. exit (2);
  66. }
  67. // copy the file into the buffer:
  68. result = fread (buffer,1,lSize,plik);
  69. if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
  70.  
  71. /* the whole file is now loaded in the memory buffer. */
  72.  
  73.  
  74. for(int j=0 ; j<lSize ;j++)
  75. {
  76. fprintf(stdout , "%c", buffer[j]);
  77. }
  78.  
  79.  
  80. fclose (plik);
  81. free (buffer);
  82.  
  83. return 0;
  84. }
Add Comment
Please, Sign In to add comment