I am on a (ubuntu exact) Linux system and I want to remove leading characters (tabs) from a string in C. I thought the following code worked on my previous installation (ubuntu oneric), but I found that it no longer works (note that this is a simplified version of the code for common UTF-8 characters):
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
int nbytes = 10000;
char *my_line, *my_char;
my_line = (char *)malloc((nbytes + 1)*sizeof(char));
strcpy(my_line,"\tinterface(quiet=true):");
printf("MY_LINE_ORIG=%s\n",my_line);
while((my_char=strchr(my_line,9))!=NULL){
strcpy(my_char, my_char+1);
}
printf("MY_LINE=%s\n",my_line);
return 0;
}
I do
gcc -o removetab removetab.c
When I execute removeetab, I get
MY_LINE_ORIG= interface(quiet=true):
MY_LINE=interfae(quiet==true):
Note the publication "=" and the missing "c"! What is wrong or how can I achieve this as an alternative. The code must support UTF-8 strings.
source
share