How to set an "empty" element in any part of an Array in C -


i'm doing program insert numbers in array, simple thing here, exemple:

if(menu==1){         system("cls");         result=lastposition(array,20);          if(result==25){             printf("\n error! array full!");             printf("\n press enter continue");             getch();         } else{          printf("\n\n\toption 1 selected: \n");          printf("\n type number add array: ");         scanf("%i",&value);          if(array[0]!=null){             printf("\n first space filled, moving itens");              changeplace(array,20,value);              printf("\n items moved success!\n");         }else {             array[0] = value;         }          printf("\n number %i added!\n",value);         printf(" press continue.\n");         getch();         } 

so, is, type number, , inserts in 20 positions array, in first position (thats why function "lastposition" there, check lastposition filled in array), if first position not filled yet(null), adds in first position, if filled, "chageplace" function moves values right, , adds number!

my problem is, when declared array, set values null, this: int array[20]={null};! in c, null change values 0, , if in program add 0 value, lets array got 5 , 10 on it, [5][10][0][0][0]...[0], i'll add zero, getting this: [0][5][10][0][0]...[0], till there ok, because c considers null=0, when try add number check if first position filled (it'll check if it's null, or 0, , return null [0]), , if try add 7 on it, replace 0 (the added number, not null) , [7][5][10][0][0]...[0]

anyone knows how fix this? someway able add 0 in function, without being replaced next number because it's considered null? having real "nothing" there, instead of "0".

ps: cant put random numbers in array, different of 0, 2 reasons, first, option 3 of menu show vector [therefore showing random number, , 2, function consider filled number!

ps²: "25" "lastposition" function returns random number i've set return if last position of array 20 (meaning full)...

this not possible in c. 1 workaround might change array elements struct having field used being boolean , field data being int.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -