- Messages
- 6,990
- Location
- Toronto, Canada
Alright I'm having trouble with this school assignment. Im on the last step and cannot figure out why it isnt working so hopefully u can tell me whats wrong. This is the code:
void Account::getFirstName(char st[])
{
int i = 0;
strcpy(st, customer);
while (st != ',')
{
i++;
}
i++;
while (st != ',')
{
strcpy(st, customer);
i++;
}
st='\0';
}
Ok let me explain. I have a string with this:
Smith,Ralph,Toronto,656-894-8574
So it goes through each letter to check if its a comma and if not keep going.
The purpose is to get rid of the last name and end chars and only keep the first name, which in this case would be Ralph without any commas. I have looked at this logic for a long time but cannot figure out where Im going wrong.
It looks so simple. But instead, I end up with Smith,Ralph left instead of only Ralph. But I don't know why it is still grabbing Smith with it.
Thanks for Your Help
Chris
void Account::getFirstName(char st[])
{
int i = 0;
strcpy(st, customer);
while (st != ',')
{
i++;
}
i++;
while (st != ',')
{
strcpy(st, customer);
i++;
}
st='\0';
}
Ok let me explain. I have a string with this:
Smith,Ralph,Toronto,656-894-8574
So it goes through each letter to check if its a comma and if not keep going.
The purpose is to get rid of the last name and end chars and only keep the first name, which in this case would be Ralph without any commas. I have looked at this logic for a long time but cannot figure out where Im going wrong.
It looks so simple. But instead, I end up with Smith,Ralph left instead of only Ralph. But I don't know why it is still grabbing Smith with it.
Thanks for Your Help
Chris