I want to take dynamic array in my program.
I have used malloc
function. In my system there is total 32 relays are present.
At a time there will be 12 relays will be off max. But in worst case it can be 32.
so I have taken size = 32
in my program. therefore i need to enter 32 values every time while testing. I want to take only 12 values at a time in array.
This is my code..
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
void main(){
int relay_check[]={0},i;
int *relay_check1;
const int size=32;
relay_check1 = (int *)malloc(sizeof(int)* size);
for(i = 0;i < size ; i++ )
{
scanf("%d",&relay_check[i]);
/*relay_check[i] is the content of element at index i and &relay_check[i] is the address of element
at index i */
}
if (!relay_check) { /* If data == 0 after the call to malloc, allocation failed for some reason */
perror("Error allocating memory");
abort();
}
for( i = 1;i < size ; ++i) {
printf("relay_check [%d]: %d\n", i, relay_check[i]);
}
for(i=1;i<9;i++){
if(i == relay_check[i] )
printf("0");
else
printf("1");
}
printf("\n");
for(i=9;i<17;i++){
if(i == relay_check[i] )
printf("0");
else
printf("1");
}
printf("\n");
for(i=17;i<25;i++){
if(i == relay_check[i] )
printf("0");
else
printf("1");
}
printf("\n");
for(i=25;i<33;i++){
if(i == relay_check[i] )
printf("0");
else
printf("1");
}
printf("\n");
getch();
}
so what else changes i need to do?