allocation and reallocation of memory dynamically of an integer array
Write a program in which you have to:
1. Dynamically allocate an array of integers.
2. Take array size as input from user and allocate memory according to this size.
3. Take values of array elements as an input from user.
4. Print all array values.
5. In this step; double the previous array size (taken in step 2) and reallocate memory for the array according to new array size. For example if user provided array size is 4; now it will become 8, i.e. allocate memory for array having size 8.
6. Now again take values for second half of the array as an input from the user to fill the increased size of an array.(You have already taken the values of first half of the array elements in step 3, now take values for remaining elements i.e. Second half).
7. Print all values of the array.
8. Also confirm that first half values of array are same in both printout statements (step 3 and step 7).
Program to dynamically Allocates an array of integers.
Enter the size of the array: 4
Enter a value: 1
Enter a value: 2
Enter a value: 3
Enter a value: 4
The elements of the array are:
1 2 3 4
Enter the elements in the array after reallocation:
Enter a value: 5
Enter a value: 6
Enter a value: 7
Enter a value: 8
1 2 3 4 5 6 7 8
Restrict user to enter only numeric entries
I need to know about how to restrict users to enter only numeric entries only and when the user enter the alphabetic character it exit the loop. I want to use the function for it.
I want to use it while getting the input of getting the size of array from user. If a user enter the alphabetic entry it doesn't execute the function and ask again for the numeric entry.
Dunno the meaning of your because
Well, If cudn't get the meaning of your because here.
& if you are saying that why I haven't posted my code here, is because of the reason that I had made it with hard work & it's the same assignment about which the query is already posted here, so I don't want any one other to copy my assignment. Once the date for that assignment will be over i'll copy the code too.
Therefore i only queried for the loop here. I think this explanation is enough for your because. Need more explanations kindly post.