[ create a new paste ] login | about

Link: http://codepad.org/DsLloBy9    [ raw code | output | fork ]

C, pasted on Nov 18:
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

struct pt {int num;int x;int y;};

struct pt* inorout(struct pt ,struct pt );
struct pt* enterarr(struct pt *);
void freeram(struct pt **);

int main()
{
    float R=7.2;
    struct pt mug[4]={1,1,1 , 2,15,1 , 3,10,8 , 4,2,14},line[2]={5,-1,-1 , 6,8,15},*D1,*D2;
    D1=(struct pt*)malloc(sizeof(struct pt)*2);
    //printf("%d %f",D1[155].y,D1[15].num);
    printf("Vvedite koordinati tochek parami cherez probel.\nroordinati tochki v promezhutke 0<=x<=20 & 0<=y<=20\n");
    
    D1=enterarr(D1);
    
    printf("%d ",D1[0].x);
    
    freeram(&D1);
    getch();
    return 0;
}
struct pt* enterarr(struct pt *arr)
{
       int i;
       
       for(i=0;i<20;i++)
       {
                        arr[i].num=i+1;
                        scanf("%d %d",&(arr[i]).x,&(arr[i]).y);
                        
                        if(((arr[i]).x < 0 || (arr[i]).x > 20) || ((arr[i]).y < 0 || (arr[i]).y > 20))
                        {
                                      i--;
                                      printf("0<=x<=20 & 0<=y<=20. REPEAT\n");
                        }
                        else arr=(struct pt*)realloc(arr,sizeof(struct pt));
       }  
       return arr; 
}

void freeram(struct pt **arr)
{
     int size,i;
     size=sizeof(*arr)*sizeof(struct pt);
     printf("size - %d\n",size);
     free(*arr);
     printf("size - %d\n",size);
     for(i=0;i<size;i++)
     {
                        printf("size - %d\n",size);
                        free(arr[i]);                   
     }
}


Output:
1
Line 18: error: conio.h: No such file or directory


Create a new paste based on this one


Comments: