Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, char* argv[]){
  7.  
  8. int des;
  9. int des2;
  10. int i;
  11. int a = 0;
  12.  
  13. if (argc == 2) {
  14. char buf[0x100];
  15. snprintf(buf, sizeof(buf), "%s", argv[1]);
  16.  
  17. des = open(buf, O_RDONLY, 0666);
  18. des2 = open("translated.txt", O_WRONLY, 0666);
  19.  
  20. if(des < 0 || des2 < 0){
  21. write( 2, "Error!\n", 7 );
  22. return 1;
  23. }
  24. } else {
  25. printf ("Nieprawidlowa liczba argumentow!\n");
  26. }
  27.  
  28. char tst[100];
  29. char tst2[100];
  30. read(des, tst, sizeof(tst));
  31.  
  32. for (i=0;i<100;i++){
  33. if ((int)tst[i] > 0) {
  34. tst2[i-a] = tst[i];
  35. }
  36.  
  37. if ((int)tst[i] < 0) {
  38. if ((int)tst[i] == -123) {
  39. a++;
  40. tst2[i-a] = 'a';
  41. }
  42. if ((int)tst[i] == -121) {
  43. a++;
  44. tst2[i-a] = 'c';
  45. }
  46. if ((int)tst[i] == -103) {
  47. a++;
  48. tst2[i-a] = 'e';
  49. }
  50. if ((int)tst[i] == -126) {
  51. a++;
  52. tst2[i-a] = 'l';
  53. }
  54. if ((int)tst[i] == -124) {
  55. a++;
  56. tst2[i-a] = 'n';
  57. }
  58. if ((int)tst[i] == -77) {
  59. a++;
  60. tst2[i-a] = 'o';
  61. }
  62. if ((int)tst[i] == -101) {
  63. a++;
  64. tst2[i-a] = 's';
  65. }
  66. if ((int)tst[i] == -68) {
  67. a++;
  68. tst2[i-a] = 'z';
  69. }
  70. if ((int)tst[i] == -70) {
  71. a++;
  72. tst2[i-a] = 'z';
  73. }
  74. }
  75. }
  76.  
  77. write(des2, tst2, sizeof(tst));
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement