How to code a program segment that can auto generate a list of ID from S0001 until S0010?
How to code a program segment that can auto generate a list of ID from S0001 until S0010?
Each time you call it, you get the next number.Code:int nextid ( ) { static int last = 0; return ++last; }
Formatting as "Snnnn" is an easy exercise for the reader.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
How to add zero between S and integer?
So I can get the same result as below:
S001
S002
S003
S004
S005
S006
S007
S008
S009
S010
Besides, take out 1 zero when reach 10.
Use printf with a format specifer that says to format the number with a certain number of digits. Refer to the documentation for printf.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"