1. If I have an array with 10 elements array[]
2. And want to split array[] to:
3. 2 new arrays:
4. 6 first elements from array[] to array New1[]
5. And new2[] with 4 last elements from array[]
Is this possible ?
1. If I have an array with 10 elements array[]
2. And want to split array[] to:
3. 2 new arrays:
4. 6 first elements from array[] to array New1[]
5. And new2[] with 4 last elements from array[]
Is this possible ?
Yes and no.
No you can't actually split array[] itself into two variables.
Yes you can create two new variables and copy the contents of array[] into those new variables.
can you show some example codes , how to create two new variables and copy the contents of array[] into those new variables ?
I would be grateful. (I have just started with C)
oldman
I won't show you how to do it but I'll show you how to initalize an array:
orCode:int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Code:int arr[10], c; for (c=0; c<10; c++) arr[c] = c + 1;
Well, think about the algorithm you'd use to go about doing it. You want the first 6 elements of one array. How do you normally access an element in an array? How do you set the contents of an array, or the contents of a particular index?
When you've figured that out, the rest is easy.
ok, thanks everybody.
You could use two pointers, one pointing at array and one at array+6. This is almost like 2 arrays, just that sizeof() will return the size of the pointers and not the arrays memory usage. At least you don't have to copy any data this way.Originally Posted by Thantos
main() { int O[!0<<~-!0]; (!0<<!0)[O]+= ~0 +~(!0|!0<<!0); printf("a function calling "); }
If you plan on using the two arrays as strings, you couldn't just use two pointers. If you did, you'd have to shift the contents of the "second array" down one, so you could include a null after the 6th character. So no, just using two pointers wouldn't do it.
Quzah.
Hope is the first step on the road to disappointment.
Basically what you say is that this method won't work if data needs to be inserted, no matter if it's a terminating \0 or any other data. That's of course true.Originally Posted by quzah
Judging by the OP's original post, that didn't seem to be his intention.
Originally Posted by oldman
main() { int O[!0<<~-!0]; (!0<<!0)[O]+= ~0 +~(!0|!0<<!0); printf("a function calling "); }
I based my answer off of the OP's question. Since h specifically used the [] symbol it ruled out he use of pointers.
You could put those behind a pointer, too .Originally Posted by Thantos
Anyway, looks like he's fine with the copy-solution so it doesn't really matter any more.
main() { int O[!0<<~-!0]; (!0<<!0)[O]+= ~0 +~(!0|!0<<!0); printf("a function calling "); }