I use the following to remove a char from a C char array by index.
In this instance, I search for the first char and if it's a 0 then remove it.
#include <stdio.h>
#include <string.h>
int main()
{
char cert_name [10];
sprintf(cert_name,"01423785");
printf("%s length:%d\n",cert_name,(int)strlen(cert_name));
if (cert_name[0] = '0')
{
printf("It seems the first char is a 0\n");
int idxToDel = 0;
memmove(&cert_name[idxToDel], &cert_name[idxToDel + 1], strlen(cert_name) - idxToDel);
}
printf("%s length:%d\n",cert_name,(int)strlen(cert_name));
return 0;
}
memmove [source]
No comments:
Post a Comment
Note: only a member of this blog may post a comment.