Your
DeleteFirst() function doesn't look right.
You use an assignment
(i = 0)
as the condition instead of a comparison of some kind. This is usually a sign of a coding mistake.
In addition,
i++ is outside the
while() loop. This is C++, not Python. Indentation doesn't affect the meaning of the code.
Here's what you probably wanted to write:
1 2 3 4 5
|
while (i == 0)
{
S[i] = 0;
i++;
}
|
That said, your code only sets the first character to 0, and prints the string starting from the second element.
Noob Programmer wrote: |
---|
can this be simplified? |
Yes, you could simply use a pointer to the second character, and print it.
(The original string will not be changed.)
1 2 3 4 5
|
char msg[] = "Hello";
const char *p = msg + 1;
std::cout << p << std::endl; // if using C++
printf("%s\n", p); // if using C
|
If using C++ you are advised to use
std::string instead of old fashioned
char arrays.
Then you could be using
std::string::substr(), among other techniques, to get a "headless" new string.
http://www.cplusplus.com/reference/string/string/substr/
If using C, you can use
memmove() to copy the string onto itself.
http://www.cplusplus.com/reference/cstring/memmove/
1 2 3 4 5 6 7
|
#include <string.h>
// ...
char msg[] = "Hello";
memmove(msg, msg + 1, sizeof msg - 1);
|