Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int i=0, k=0; // Common variables for loops
- // -----------------------------
- char pairs[100][20]; // here would be extracted pairs in text format
- for(i=0;i<100;i++) // to avoid garbage set all to zero
- for(k=0; k<20; k++)
- pairs[i][k] = 0;
- // -----------------------------
- int bound[100][2]; // here would be pairs in int format (the result)
- // READING IN "text" UNTIL EOF
- int c;
- char text[100]="";
- int n=0;
- c = getchar();
- while(c!=EOF){
- text[n] = (char) c;
- c = getchar();
- n++;
- }
- n--; // Amount of characters entered
- //-----------------------------
- // EXTRACTING PAIRS FROM "text" to "pairs[i]"
- int start, stop; // indexes of < and >
- int p=0; // Amount of pairs
- while(p<=n){ // extra condition (if zero input)
- printf("\n\t[debug] text = %s", text);
- // initialize
- start = -1;
- stop = -1;
- // finding indexes
- for(i=0; i<=n; i++)
- if(text[i] == '<'){
- start = i;
- printf("\n\t\t[debug] start=%i", start);
- break;
- }
- for(i=0; i<=n; i++)
- if(text[i] == '>'){
- stop = i;
- printf("\n\t\t[debug] stop=%i", stop);
- break;
- }
- k=0;
- if(start!=-1 && stop!=-1){ // if found
- for(i=start; i<=stop; i++){ // fill pairs[p] with text between < and > in main variable
- pairs[p][k]=text[i];
- text[i] = ' '; // and erase it from main variable
- k++;
- }
- printf("\n\t[debug] extracted pair = %s", pairs[p]);
- p++; // increase amount of already founded pairs
- }
- else{
- printf("\n\t[debug] Searching done");
- break; // exit loop when nothing found (because we erased every found pair)
- }
- printf("\n");
- }
- // ---------------------------------------------
- // CONVERTING WITH FILTER FROM "pairs[i]" TO "bound[i]"
- printf("\n");
- printf("\n\t[debug]Converting started:\n");
- int dc, num;
- for(i=0; i<p; i++){
- printf("\n\t[debug] scanning: %s", pairs[i]);
- dc=0; // Amount of dot-coma
- for(k=0; k<20; k++)
- if(pairs[i][k] == ';')
- dc++;
- if(dc==1){
- num = sscanf(pairs[i], "<%d; %d>", &bound[i][0], &bound[i][1]);
- if(num!=2){
- printf("\n\t[debug] error reading value");
- bound[i][0] = 0;
- bound[i][1] = 0;
- }
- }else{
- printf("\n\t[debug] too much or no ';'");
- bound[i][0] = 0;
- bound[i][1] = 0;
- }
- printf("\n\t[debug] scanned in this pair: %d %d", bound[i][0], bound[i][1]);
- printf("\n");
- }
- // ---------------------------------
- printf("\n\n");
- // RESULTS
- for(i=0;i<p;i++){
- printf("\n\t[debug] [RESULT] bounds = %d %d", bound[i][0], bound[i][1]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement