Ash Ash - 1 year ago 98
C Question

How to remove first character from C-string?

Can anyone please help me? I need to remove the first character from a

char *
in C.

For example,
char * contents
contains a
character as the first character in the array. I need to detect and eliminate this character, modifying the original variable after its been "sanitized".

Can anyone help me with the code? I'm completely new to C, and just can't seem to figure it out.

Answer Source
if (contents[0] == '\n') 
    memmove(contents, contents+1, strlen(contents));

Or, if the pointer can be modified:

if (contents[0] == '\n') contents++;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download