suppose an array is initialized as s[]={1, 2, 3, 4, 5}
i would like to delete elements 1 to 3.. i.e 2, 3 and 5..
the remaining array has to look like s[]= {1, 5}
how can this be done?
suppose an array is initialized as s[]={1, 2, 3, 4, 5}
i would like to delete elements 1 to 3.. i.e 2, 3 and 5..
the remaining array has to look like s[]= {1, 5}
how can this be done?
An array is not a particularly well suited data structure for that operation. What you want is a linked list.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
You can't delete the actual elements of the array (like you can with the nodes of a linked list), but you can remove the VALUES in those array elements.
If zero means the same as "nothing" in your program, you can use it as your "sentinel" value. I've used INT_MAX and INT_MIN as sentinel values for this purpose. (include <limits.h> to use these macro's).
For taking average scores, printing out the array, and what not, you need to adjust all your logic a bit to ignore that sentinel value.Code:for(i=low; i<=high;i++) myArray[i] = INT_MIN;
You can use memmove().
e.g memmove(s+1,s+4,sizeof(int) * 1 );