so guys, i was thinking about finding a way to create arrays, without knowing their size.
for example
create an app that takes unsigned long values until EOF and just saves them to an unknown size array.
i was thinking that, because the array size could be big, to create the array using dynamic memory allocation.
so here is my code which is NOT correct thats why i need your help
#include <stdio.h>
#include <stdlib.h>
int main(){
unsigned long n,count=0,*array,size=1,i;
while((scanf("%ul",&n))!=EOF){
count=count+1;
array =(long*)malloc(count*sizeof(long));
array[count] = n;
if (count>size){
size=count;
}
if (n==5){
break;
}
}
for (i=1;i<=size;i++){
printf("%ul\n",array[i]);
}
free(array);
return 0;
}
my first problem is that, when the app takes the forth value for variable un it just sticks, and does nothing.
also when i try for 3 numbers, it doesnt print them in the end correctly it prints numbers like 2938928329 etc
i would like some help to achieve that, dont tell me other ways, i know there are other ways.
thanks in advance :)