#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int Init_Arr(int N,int X,int *arr);
void Add_elem(int N,int *arr);
void Del_elem(int N,int *arr);
void Reinit_arr(int N,int *arr);
int main(){
int N,X,*arr;
printf("How big array do you want?:");
scanf("%d",&N);
arr=(int *)malloc(sizeof(N));
printf("\nHow much elements do you want in your array?:");
scanf("%d",&X);
Init_Arr(N,X,arr);
Add_elem(N,arr);
Del_elem(N,arr);
Reinit_arr(N,arr);
return 0;
}
int Init_Arr(int N,int X,int *arr){
for (int i=0;i<N;i++){
arr[i]=0;
}
for(int i=0;i<X;i++){
arr[i]=rand()%10+1;
}
for(int i=0;i<N;i++){
printf("%d",arr[i]);
}
printf("\nArray is initialised!\n");
return 0;
}
void Add_elem(int N,int *arr){
int add;
int help;
int i=0;
printf("\nWhat element do you want to add?:");
scanf("%d",&add);
while(arr[i]!=0){
i++;
}
arr[i]=add;
for(int i=0;i<N;i++){
printf("%d",arr[i]);
}
printf("\nElement was added to array!\n");
}
void Del_elem(int N,int *arr){
int del;
printf("\nWhat element do you want to delete from array?:");
scanf("%d",&del);
arr[del]=0;
for(int i=0;i<N;i++){
printf("%d",arr[i]);
}
printf("\nElement was deleted from array!\n");
}
void Reinit_arr(int N,int *arr){
int *copyarr;
int D;
copyarr=(int *)realloc(sizeof(N));
for(int i=0;i<N;i++){
copyarr[i]=arr[i];
}
printf("How big array now do you want?:");
scanf("%d",&D);
arr=(int*)realloc(arr,sizeof(D));
for(int i=0;i<N;i++){
arr[i]=copyarr[i];
}
for(int i=N;i<D;i++){
arr[i]=0;
}
for(int i=0;i<D;i++){
printf("%d",arr[i]);
}
printf("\nArray was reinitialised\n");
}
Well,this program should be working in following way:initiate a dynamic string, fill it with X random elements, then add any element to the end of positive numbers string, delete any element(just setting it to 0) of array and the problem function:reallocate memory and make the string bigger, with the inside copied. the problem is that it just says "Aborted" at the function
Reinit_arr(N,arr);
GDB said that after trying this function the program returned the following:raise.c: no such file or directory. can you help me with it?