remove last character in char

hey alll

this my code :

...
char tmp[5] ;
int id;
cout << "enter an id " << endl;
cin >> id ; ( for exemple 1234 )

....

itoa(id,tmp, 10); <------- transform id to char

how can i remove the last character in tmp to get 123 ?

I don't think your char is long enough to be safely used with itoa(). To actually answer your question, however, I would just set temp[3] = '\0' which would end the C-string.
Why not just input directly into id and then divide by ten?
then how do i convert from int to char then remove the last character ? any better ideas !
Is that a requirement of an assignment or something? What helios suggested is pretty much the best you can do.
i didnt catch wut helios suggested, can anyone explain?
helios means
1
2
3
cin >> id;
id/=10;
cout << id << endl;
That works great with int. If it wasn't an int you would have to search the char array for (hopefully) the null character('\0') and then set the previous index to '\0'.
Sure, but why bother when in the OPs example the char array is just being used to convert to an int anyway?
Topic archived. No new replies allowed.