hello eveyone
i'm making an Inventory for a game and i'm having a problem.
what i want is to search the array for NULL and if it finds NULL change it from NULL to 'T', now the problem is that if it finds more than 1 NULL it will change all NULLs to 'T' but that is not what i want, what i want is to change only the first NULL it finds to 'T'.
example
array[10]={NULL,NULL,NULL,'R','M',NULL,'S',NULL,NULL,P'}
Search for the first NULL and get the index, so first NULL index = 0, so change index 0 to NULL;
so it will look like this
array[10]={'T',NULL,NULL,'R','M',NULL,'S',NULL,NULL,P'}
NOT LIKE THIS
array[10]={'T','T','T','R','M','T','S','T','T',P'}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
using namespace std;
int main()
{
char Inventory[10]={'A',NULL,'B','C',NULL,'D','E','F','G','H'};
for(int x=0; x<=9; x++)
cout<< Inventory[x] << endl;
cout << "------------------------------" << endl;
int FistNum=0, LastNum=9;
for(int x=FistNum; x<=LastNum; x++)
{
if(Inventory[x]==NULL)
{
Inventory[x]='T';
}
}
for(int x=0; x<=9; x++)
cout<< Inventory[x] << endl;
system("PAUSE");
return 0;
}
|