Я пытаюсь выяснить, как скопировать обрезанную строку с удаленными начальными пробелами и сохранить в массиве dest с помощью указателя / без указателя.
Это то, что я пробовал.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void trim_copy(char dest[], char src[]){
char *p = src;
size_t i;
size_t counter = 0;
size_t length = strlen(src);
while(!isspace(src[counter]) && counter < length){
p++;
counter++; /*move the pointer to next index of string if it's a space*/
}
for (i = 0; i< length-counter; i++) {
dest[i] = *p;
p++;
}
}
int main(void){
char string_with_space_dest[20];
ltrim_copy(string_with_space_dest, " hello");
printf("after removing leading space %s\n",string_with_space_dest );
return 0;
}
Распечатывает:
after removing leading space hello
Компилируется, но не работает вообще.
что если массив src был const и вы не можете использовать указатель?
void trim_copy(char dest[], const char src[]){}