#c #memcpy
Вопрос:
Я пытаюсь переместить содержимое массива структур.
#include<stdio.h>
#include<string.h>
typedef struct {
char texts[1024];
}text_i;
text_i textlist[5];
int main()
{
int ind;
strcpy( textlist[0].texts, "hello ..");
strcpy( textlist[1].texts, "world ..");
printf("texts before memcpyn");
for (ind = 0; ind < 5 ; ind )
printf("texts ind(%d) is %s n", ind, textlist[ind].texts);
memcpy( amp;textlist[1], amp;textlist[0], 4 * sizeof(text_i));
printf("texts after memcpyn");
for (ind = 0; ind < 5 ; ind )
printf("texts ind(%d) is %s n", ind, textlist[ind].texts);
}
Это выведет весь список из 5 texts
в строку hello ..
.
texts before memcpy
texts ind(0) is hello ..
texts ind(1) is world ..
texts ind(2) is
texts ind(3) is
texts ind(4) is
texts after memcpy
texts ind(0) is hello ..
texts ind(1) is hello ..
texts ind(2) is hello ..
texts ind(3) is hello ..
texts ind(4) is hello ..
Мое намерение состояло в том , чтобы переместить текстовый список[0] в текстовый список[1], текстовый список[1] в текстовый список[2], текстовый список[2] в текстовый список[3] и так далее.
ожидаемый:
texts ind(0) is hello ..
texts ind(1) is hello ..
texts ind(2) is world ..
texts ind(3) is
texts ind(4) is
Я не хочу ind(3)
и ind(4)
не хочу, чтобы меня трогали. Что можно было бы сделать, чтобы получить его в вышеуказанном формате?
Комментарии:
1. Я думаю, вы используете C, а не C ? Можете ли вы удалить один из тегов в своем вопросе?