I'm an MIS major whos trying to maintain his programming skills (as my job in not related to programming).
Basically, i need help creating a dynamic array.
The idea is, to allow the user to input data (ages, scores, etc), as many times as needed. Here is a semi generic code snippet that i've come up with.
#include<stdio.h>
int main()
{
int i; /* declare counter */
int age[]; /* declare array "age" */
do { /* initialize array */
i=i+1; /* tracks iterations*/
printf("Enter age"); /* prompt user for value*/
scanf("%d", age[i]);} /*accept input from user*/
while(age[i] != 0); /* terminate loop when user inputs 0*/
return 0; /* return 0 if no errors*/
}
Everything ive come across on the web assumes that the user knows how big the array needs to be. I'm sure C can handle this, but i don't know if there is a specific function i should use, or if i have to work around it.
Any help is appreciated.
Thanks
Edited by dargueta, 20 January 2011 - 12:03 AM.
Added code tags


Sign In
Create Account

Back to top









