38 lines
671 B
C
38 lines
671 B
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
int cols, rows;
|
||
|
|
||
|
void insert (char (*content)[cols], char* toInsert) {
|
||
|
int i = rows;
|
||
|
for (i; i > 0; i --) {
|
||
|
strcpy(content[i], content[i - 1]);
|
||
|
}
|
||
|
strcpy(content[i], toInsert);
|
||
|
}
|
||
|
|
||
|
int main () {
|
||
|
cols = 20;
|
||
|
rows = 3;
|
||
|
|
||
|
char (*content)[cols] = malloc(sizeof(char[rows][cols+1]) * 10);
|
||
|
|
||
|
strcpy(content[0], "Test string 1");
|
||
|
strcpy(content[1], "Test string 2");
|
||
|
|
||
|
printf("Array before insert: \n");
|
||
|
|
||
|
for (int i = 0; i < 3; i ++) {
|
||
|
printf("%s\n", content[i]);
|
||
|
}
|
||
|
|
||
|
insert(content, "test string 0");
|
||
|
|
||
|
printf("Array after insert: \n");
|
||
|
|
||
|
for (int i = 0; i < 3; i ++) {
|
||
|
printf("%s\n", content[i]);
|
||
|
}
|
||
|
}
|