Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FileHandler.h"
- #include< stddef.h >
- void copy(char*, char*);
- void append(char*, char*);
- void split(char*, char,char**);
- int main()
- {
- int num[2]={0,0}, i = 0, j = 0,mark;
- char* fileinput = readAllTextFromFile("./input.txt");
- while (*(fileinput + i) != NULL) {
- while (*(fileinput + i) != '\n' && *(fileinput + i) != NULL) {
- if (j < 2) num[j]++; else if (j == 2) mark = i;
- i++;
- }
- i++;
- j++;
- }
- char* str = malloc(num[0] * sizeof(char));
- char* copyed = malloc(num[0] * sizeof(char));
- char* inputappend = malloc(num[1] * sizeof(char));
- char splitchar = *(fileinput + mark);
- char** splitresult = malloc((num[0]+num[1]) * sizeof(char));
- for (i = 0; i < num[0]; i++) {
- *(str + i) = *(fileinput + i);
- }
- *(str + num[0]) = '\0';
- printf("Input string:%s\n\n",str);
- for (i = 0; i < num[1]; i++) {
- *(inputappend + i) = *(fileinput + i+1+ num[0]);
- }
- *(inputappend + num[1]) = '\0';
- printf("append text:%s\n", inputappend);
- copy(str, copyed);
- append(str, inputappend);
- printf("append result:%s\n\n", str);
- printf("original string:%s\n\n", copyed);
- printf("split char:%c\n", splitchar);
- split(str, splitchar,splitresult);
- printf("split resilt:%s\n", splitresult);
- return 0;
- }
- void copy(char* src, char* dist) {
- int i = 0;
- while (*(src + i) != '\0') {
- *(dist + i) = *(src + i);
- i++;
- }
- *(dist + i) = '\0';
- }
- //append the text after target.
- void append(char* target, char* text) {
- int i = 0,j=0;
- while (*(target + i) != '\0') {
- i++;
- }
- while (*(text+ j) != '\0') {
- j++;
- }
- target=realloc(target, (i + j) * sizeof(char));
- for (int k = 0; k < j; k++) {
- *(target + i + k) = *(text + k);
- }
- *(target + i + j) = '\0';
- }
- //split src string by target, then output by segments.
- void split(char* src, char target,char** segments) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement