Advertisement
j0h

xmlParse.c

j0h
Apr 16th, 2023 (edited)
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int  main(int argc, char **argv){
  6.  FILE* fp;
  7.  char s[2048];
  8.        char *r1=NULL;
  9.        char *x1=NULL;
  10.        int rectCount=0;
  11.  // Open UI file to read
  12.  fp = fopen("3btn.ui", "r");
  13.  
  14.  if ( fp == NULL ){
  15.  printf("File error, can't read! \n");
  16.  }else {
  17.           while( !feof(fp) ) {
  18.                       fgets(s, 2047, fp ); //max 2047 char
  19.                       r1= strstr(s, "<rect>");
  20.           if(r1!=NULL){
  21.               fgets(s, 2047, fp );
  22.               x1=strstr(s,"<x>");
  23.               rectCount++;
  24.           if(x1!=NULL){
  25.               char num[strlen(x1)]; //N in the array fits in size of x1
  26.               int  j = 0, len;
  27.               len = strlen(x1);
  28.                   for (int i = 0; i < len; i++) {
  29.                           if (x1[i] >= '0' && x1[i] <= '9') {
  30.                                num[j] = x1[i];
  31.                                j++;
  32.                                }
  33.                     }
  34.                   printf("The innner value is: %d\n", atoi(num));
  35.              }
  36.                    r1=NULL;
  37.                    x1=NULL;
  38.              }
  39.           };      //end while loop
  40.     printf("\n%d", rectCount);
  41.  fclose(fp);
  42.  }
  43.   return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement