c - Trimming a string of Int -
in program want input string of integer e.g 2107900000. want length , want remove 0's , 1's.
perhaps not optimal, copy buffer conditionally:
char buffer[20]; char num[] = "2107900000"; int j = 0; (int = 0; num[i]; i++) { if (num[i] != '0' && num[i] != '1') { buffer[j] = num[i]; j++; } } buffer[j] = 0 //null terminator
or in single buffer:
char num[] = "2107900000"; int j = 0; (int = 0; num[i]; i++) { if (num[i] != '0' && num[i] != '1') { num[j] = num[i]; j++; } } num[j] = 0 //null terminator
Comments
Post a Comment