Created
May 29, 2019 09:15
-
-
Save moomdate/9bf238ccb9f6307d56d4d316e07ad2e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<string.h> | |
| #include <stdlib.h> | |
| #define EndSign ':' | |
| #define MarkMaxBufferPage 20 | |
| void searchName(char * fileName); // search file | |
| void filterPageToArray(int pS,int pE); // data string to num array | |
| int getEndSign(int startAt); //get position of end string | |
| int MarkerPage[MarkMaxBufferPage]; // buffer | |
| void printfPageOfMarker(); // print lst | |
| int findIndexOfArray(int target); // find index of line | |
| int RemoveArrayAtIndex(int position); | |
| int findIndexForInsert(int value); | |
| int insertMark(int); | |
| int sizeOfList(); | |
| char * data = "test.brf5/10/15/20/:test2.brf1/4/5/12/55/:test99.brf0/254/525/1000/:"; | |
| int main(){ | |
| searchName("test.brf"); | |
| printf("*befor remove size (%d)--\r\n",sizeOfList()); | |
| printfPageOfMarker(); | |
| printf("#max index (%d) \r\n",findIndexOfArray(4)); | |
| if(insertMark(4)){ | |
| printf("oK\r\n"); | |
| } | |
| printfPageOfMarker(); | |
| /*printf("index - %d\r\n",findIndexOfArray(11)); | |
| RemoveArrayAtIndex(findIndexOfArray(10)); | |
| printf("*after Remove size (%d)--\r\n",sizeOfList()); | |
| printfPageOfMarker();*/ | |
| //printf("end of Name %d",getEndSign(0)); | |
| return 0; | |
| } | |
| void printfPageOfMarker(){ | |
| int cc = 0; | |
| while(MarkerPage[cc]!=NULL){ | |
| printf("page:%d\r\n",MarkerPage[cc]); | |
| cc++; | |
| } | |
| } | |
| void searchName(char * fileName){ | |
| int pos; | |
| int startPos,EndPos; | |
| char *ptr; | |
| ptr = strstr(data,fileName); | |
| if(ptr != NULL){ | |
| startPos = ptr-data; // find start index | |
| startPos = strlen(fileName) + startPos; | |
| EndPos = getEndSign(startPos); // find end index | |
| printf("end :%c\r\n",data[EndPos]); // index | |
| printf("file name %s\r\n",fileName); | |
| printf("start at (%d), end at (%d)\r\n", startPos,EndPos); | |
| printf("char start (%c), end (%c)\r\n",data[startPos],data[EndPos]); | |
| filterPageToArray( startPos,EndPos); | |
| }else{ | |
| printf("not found\r\n"); | |
| } | |
| } | |
| int getEndSign(int StartAt){ | |
| int ccCO; | |
| int DataSize; | |
| DataSize = strlen(data); | |
| //printf("data size:%d",DataSize); | |
| ccCO = StartAt; | |
| while(ccCO < DataSize){ | |
| if(data[ccCO]==':') | |
| break; | |
| if(ccCO>DataSize) | |
| break; | |
| ccCO++; | |
| } | |
| return ccCO; | |
| } | |
| void filterPageToArray(int pStart,int pEnd){ | |
| int countDigit = 0; | |
| int numPrepare = 0; | |
| int arrayIndex = 0; | |
| int count = pStart; | |
| char buffNumber[7]; | |
| while(count<pEnd){ | |
| //printf("%c",data[count]); | |
| if(data[count]>=48&&data[count]<=57){ // is number | |
| //printf("%c\r\n",data[count]); | |
| buffNumber[countDigit++] = data[count]; | |
| }else if(data[count]==47){ // is slash | |
| // push to array here | |
| numPrepare = atoi (buffNumber); | |
| memset(buffNumber,0,sizeof(buffNumber)); | |
| MarkerPage[arrayIndex] = numPrepare; | |
| arrayIndex++; | |
| //printf("number is %d\r\n",numPrepare); | |
| countDigit = 0; | |
| } | |
| count++; | |
| } | |
| arrayIndex = 0; | |
| count = 0; | |
| countDigit = 0; | |
| //printf("start %c, end %c",data[pStart],data[pEnd]); | |
| } | |
| int RemoveArrayAtIndex(int position){ | |
| int c; | |
| int n; | |
| n = sizeOfList(); | |
| //printf("size of list %d\r\n",n); | |
| for (c = position ; c < n; c++) | |
| MarkerPage[c] = MarkerPage[c+1]; | |
| MarkerPage[c] = 0x00; //clear | |
| return 1; | |
| } | |
| int sizeOfList(){ | |
| int cc = 0; | |
| while(MarkerPage[cc]!=NULL){ | |
| cc++; | |
| } | |
| return cc; | |
| } | |
| int findIndexOfArray(int target){ | |
| int cc = 0; | |
| while(MarkerPage[cc]!=NULL){ | |
| if(MarkerPage[cc]==target) | |
| break; | |
| cc++; | |
| } | |
| return cc; | |
| } | |
| int findIndexForInsert(int value){ | |
| int cc; | |
| cc = sizeOfList()-1; | |
| //printf("aaaaaaaaaaaaaaaaa %d\r\n",cc); | |
| while(cc>=0){ | |
| if(value>MarkerPage[cc]) | |
| break; | |
| cc--; | |
| } | |
| cc++; | |
| //printf("cc = %d\r\n",cc); | |
| return cc; | |
| } | |
| int insertMark(int line){ | |
| int n,index; | |
| int cc = 0; | |
| int position; | |
| n = sizeOfList(); | |
| index = findIndexOfArray(line); | |
| position = findIndexForInsert(line); // find | |
| //printf("n = %d index %d---------\r\n",n,index); | |
| if(index!=n) | |
| { | |
| return 0; //error; | |
| }else{ | |
| for (cc = n - 1; cc >= position - 1; cc--) | |
| MarkerPage[cc+1] = MarkerPage[cc]; | |
| MarkerPage[position] = line; | |
| return 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment