Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <malloc.h>
- int PEEK(FILE* IN, int** stack, int* stack_mem) {
- printf("PEEK 1-");
- static FILE* in = NULL;
- if (IN == in) {
- if (!IN) {
- printf("FILE* = NULL first time");
- return 2;
- }
- }
- in = IN;
- printf("2-");
- int k = fscanf_s(in,"%i", stack[(*stack_mem)-1]);
- if (k == 0) {
- printf("Wrong File Format");
- return 1;
- }
- else {
- if (k < 0) {
- printf("EOF - input File");
- return 2;
- }
- }
- printf("3-");
- printf("[%i]=",*stack[((int)*stack_mem) - 1]);
- printf("[%i]-", (*stack_mem + 1));
- int* secure;
- secure = (int*)realloc(*stack , (1+(*stack_mem)) * sizeof(int) );
- if (secure == NULL) {
- printf("Out_Of_Memory [PEEK(stack_mem=%i)]", (*stack_mem)+1);
- return 2;
- }
- *stack = secure;
- free(secure);
- (*stack_mem)++;
- //printf("4-StacKmem[%i]\n",*stack_mem);
- return 0;
- }
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<malloc.h>
- int main(){
- int* stack;
- int stack_mem = 1;
- stack = (int*)calloc(stack_mem,sizeof(int));
- FILE *IN, *OUT;
- IN = fopen("input.txt","r");
- OUT = fopen("output.txt", "w");
- //IN = freopen("input.txt", "r", stdin);
- PEEK(IN, &stack, &stack_mem);
- PEEK(IN, &stack, &stack_mem);
- PEEK(IN, &stack, &stack_mem);
- printf("FREE_stage");
- free(stack);
- fclose(IN);
- fclose(OUT);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement