Hi I need to have an array in my program that is defined by the user. I just need the user to enter the size of the array and then enter the integer values that they want to store in the array.
I know how to declare the array myself, and Ive looked around and I cant find a straightforward solution to my problem. Any help/suggestions will be greatly appreciated.
Thankyou
TrueCoding
TrueCoding
7
Junior Poster in Training
Recommended Answers
Jump to Postscanf is the input function in C. You'll want to ask the user for the size of the array, and then have a loop that reads their numbers. Do you know how to do a loop?
Jump to Postif you are not new to C language then you can use malloc or calloc function to create your Arrays..
Jump to Post…# include <stdio.h> # define MAX 100 int main(void) { int array[MAX],i,n; printf("\n Enter Array size (1 - %d):",MAX); scanf("%d", &n); for(i = 0; i < n; i++) { printf("\n Enter %d value :",i+1); scanf("%d", &array[i]); } // whatever else you want to do....... return 1; }
All 11 Replies
Dervish1
37
Newbie Poster
TrueCoding
7
Junior Poster in Training
vinitmittal2008
37
Junior Poster
TrueCoding
7
Junior Poster in Training
vinitmittal2008
37
Junior Poster
TrueCoding
7
Junior Poster in Training
vinitmittal2008
37
Junior Poster
TrueCoding
7
Junior Poster in Training
vinitmittal2008
37
Junior Poster
TrueCoding
7
Junior Poster in Training
vinitmittal2008
37
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.