Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. char *readFile(char *fileName) {
  7. FILE *file = fopen(fileName, "r");
  8. char *code;
  9. size_t n = 0;
  10. int c;
  11.  
  12. if (file == NULL) return NULL;
  13. fseek(file, 0, SEEK_END);
  14. long f_size = ftell(file);
  15. fseek(file, 0, SEEK_SET);
  16. code = malloc(f_size);
  17.  
  18. while ((c = fgetc(file)) != EOF) {
  19. code[n++] = (char)c;
  20. }
  21.  
  22. code[n] = '\0';
  23.  
  24. return code;
  25. }
  26.  
  27. int main()
  28. {
  29. FILE *output = fopen("c.txt", "w");
  30.  
  31. if(!output)
  32. exit(1);
  33.  
  34. char *input = readFile("a.txt");
  35. char *input_b = readFile("b.txt");
  36.  
  37. if(!input)
  38. exit(2);
  39.  
  40. if(!input_b)
  41. exit(3);
  42.  
  43. for(int i = 0; i < strlen(input); i++)
  44. {
  45. char in = input[i];
  46. if(in == '<' || in == '>' || in == '=')
  47. {
  48. fputc(in, output);
  49. fputc(' ', output);
  50. }
  51. }
  52.  
  53. for(int i = 0; i < strlen(input_b); i++)
  54. {
  55. char in = input_b[i];
  56. if(islower(in))
  57. {
  58. fputc(in, output);
  59. fputc(' ', output);
  60. }
  61. }
  62.  
  63. fclose(output);
  64.  
  65. printf("Done!\n");
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement