This one should be nice and easy for all the experienced programmers out there, but I've been struggling to find a way to delete a single character from a short string.
The string takes the form x7784 or similar, where the numbers could be anything, between 1 and 9999, and the x is a single character at the start of the string.
I know how to convert a string to an integer (atoi works well for what I need to do), but unfortunately I have that annoying character at the front, and I am stuck as to how to remove it.
Even copying the digits at the end to a new string would be an acceptable solution, but unfortunately I'm struggling with that idea too...
Any help much appreciated!
EDIT: I should qualify; the input is from the command line, and argv[2] is the place where my problem resides... (So it's a pointer to a string...)
You just need a pointer that will point to 1 (char sized) space after the start of the string. Hence pointer indexing is what you need. This is not the only way, nor the "simplest", but it's probably the most straight-foward for what you're talking about.
1 2 3 4
char * new_pointer; //new string (char *) pointer for number string
int integer_variable; //integer var for holding atoi result
new_pointer=argv[2]+1; //sets new pointer to the adress of the second character in the series
integer_variable=atoi(new_pointer); //performs the change to integer.