I have this code in here:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void array_input(int *a)
{
int i=0,n,p;
printf("How many items you wanna input? : ");
scanf("%d", &p);
for(n = 0; n <= 99; n++)
if(*(a+n) != 0)
i++;
for(i; i<(i+p); i++)
{
printf("Enter %d number:",i);
scanf("%d", &(*(a+i)));
}
}
int main(void)
{
int n,t=1;
int arrays[99] = {30};
while(t)
{
n = getch();
switch(n)
{
case '1':
printf("Imput numbers into array!\n");
array_input(arrays);
break;
case '2':
printf("Excute the array into file!\n");
break;
case '3':
printf("Exit");
//t=0;
break;
default:
printf("Wrong choice");
break;
}
}
}
Actually when I run it everything is going by plan until i get here:
for(i; i<(i+p); i++)
{
printf("Enter %d number:",i);
scanf("%d", &(*(a+i)));
}
This for is running beyond all limits. If i have 1 number in array which is 30 and i wanna input 2 new numbers it the (i+p) should be 1+2 = 3 okay, then the restriction become 3 its go one and not stopping?
Can some one helps me on this one ?