c - I am getting a run time error for the following code -
#include<stdio.h> #include<stdlib.h> int main() { int i, j, a[10], result = 0,p; int *m = malloc(sizeof(int)*8); for(i = 0; < 10; i++){ scanf("%d", &a[i]); result += a[i]; } //printf("%d\n", result); //printf("\n"); //for(i = 0; < 8; i++) { for(j = 0; j < 9; j++) { scanf("%d", &m[j]); result = result - m[j]; p = result / 2; } return p; }
in code getting runtime error. appreciated. thanks!
insufficient memory allocated.
int *m=malloc(sizeof(int)*8); // 8 `int` ... for(j=0;j<9;j++){ scanf("%d",&m[j]); // attempt set the 9th `int`, m[8]
allocate sufficient memory.
#define jsize 9 int *m=malloc(sizeof *m * jsize); if (m == null) handle_outofmemory(); ... for(j=0;j<jsize;j++){ if (scanf("%d",&m[j]) != 1) handle_badinput();
Comments
Post a Comment