|
@@ -1,63 +0,0 @@
|
|
|
-#include <stddef.h>
|
|
|
|
|
-#include <stdio.h>
|
|
|
|
|
-#include <stdlib.h>
|
|
|
|
|
-#include <string.h>
|
|
|
|
|
-
|
|
|
|
|
-struct stringchicken{
|
|
|
|
|
- char **data;
|
|
|
|
|
- size_t length;
|
|
|
|
|
- size_t capacity;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-struct stringchicken *create_string_chicken(){
|
|
|
|
|
- struct stringchicken *mystruct = malloc(sizeof(struct stringchicken));
|
|
|
|
|
- mystruct->length = 0;
|
|
|
|
|
- mystruct->capacity = 2;
|
|
|
|
|
-
|
|
|
|
|
- mystruct->data = malloc(sizeof(char*) * mystruct->capacity);
|
|
|
|
|
-
|
|
|
|
|
- return mystruct;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void push_SC(char *string_input, struct stringchicken *struct_input){
|
|
|
|
|
-
|
|
|
|
|
- if (struct_input->length == struct_input->capacity) {
|
|
|
|
|
- struct_input->capacity*=2;
|
|
|
|
|
- char **tempptr = realloc(struct_input->data, sizeof(char*) * struct_input->capacity);
|
|
|
|
|
-
|
|
|
|
|
- if (tempptr == NULL) {
|
|
|
|
|
- exit(1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- struct_input->data = tempptr;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- char *newstring = malloc(strnlen(string_input, sizeof(char)*100));
|
|
|
|
|
- strcpy(newstring,string_input);
|
|
|
|
|
- struct_input->data[struct_input->length] = newstring;
|
|
|
|
|
-
|
|
|
|
|
- struct_input->length++;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void printchicken(struct stringchicken *input_struct){
|
|
|
|
|
- for (size_t i = 0; i < input_struct->length; i++) {
|
|
|
|
|
- printf("line:%zu equals %s", i, input_struct->data[i]);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-int main() {
|
|
|
|
|
- char myString[100];
|
|
|
|
|
- char ch;
|
|
|
|
|
- FILE *fptr = fopen("./kvtest.txt", "r");
|
|
|
|
|
-
|
|
|
|
|
- struct stringchicken *mystringarray = create_string_chicken();
|
|
|
|
|
-
|
|
|
|
|
- while (fgets(myString, 100, fptr)) {
|
|
|
|
|
- push_SC(myString, mystringarray);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- printchicken(mystringarray);
|
|
|
|
|
- int mylength = strnlen(myString, 100);
|
|
|
|
|
-
|
|
|
|
|
- fclose(fptr);
|
|
|
|
|
-}
|
|
|