Advertisement
Guest User

12345

a guest
Nov 12th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #define CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <malloc.h>
  4.  
  5. int PEEK(FILE* IN, int** stack, int* stack_mem) {
  6. printf("PEEK 1-");
  7. static FILE* in = NULL;
  8. if (IN == in) {
  9. if (!IN) {
  10. printf("FILE* = NULL first time");
  11. return 2;
  12. }
  13. }
  14. in = IN;
  15. printf("2-");
  16. int k = fscanf_s(in,"%i", stack[(*stack_mem)-1]);
  17. if (k == 0) {
  18. printf("Wrong File Format");
  19. return 1;
  20. }
  21. else {
  22. if (k < 0) {
  23. printf("EOF - input File");
  24. return 2;
  25. }
  26. }
  27. printf("3-");
  28. printf("[%i]=",*stack[((int)*stack_mem) - 1]);
  29. printf("[%i]-", (*stack_mem + 1));
  30.  
  31. int* secure;
  32. secure = (int*)realloc(*stack , (1+(*stack_mem)) * sizeof(int) );
  33. if (secure == NULL) {
  34. printf("Out_Of_Memory [PEEK(stack_mem=%i)]", (*stack_mem)+1);
  35. return 2;
  36. }
  37. *stack = secure;
  38. free(secure);
  39. (*stack_mem)++;
  40. //printf("4-StacKmem[%i]\n",*stack_mem);
  41. return 0;
  42. }
  43.  
  44. #define _CRT_SECURE_NO_WARNINGS
  45. #include<stdio.h>
  46. #include<malloc.h>
  47.  
  48. int main(){
  49. int* stack;
  50. int stack_mem = 1;
  51.  
  52. stack = (int*)calloc(stack_mem,sizeof(int));
  53.  
  54. FILE *IN, *OUT;
  55. IN = fopen("input.txt","r");
  56. OUT = fopen("output.txt", "w");
  57.  
  58. //IN = freopen("input.txt", "r", stdin);
  59.  
  60. PEEK(IN, &stack, &stack_mem);
  61.  
  62. PEEK(IN, &stack, &stack_mem);
  63.  
  64. PEEK(IN, &stack, &stack_mem);
  65. printf("FREE_stage");
  66. free(stack);
  67. fclose(IN);
  68. fclose(OUT);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement