#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ROW 10
#define COLS 10
int a[ROW][COLS] = {
1,1,1,1,1,1,1,1,1,1,\
1,1,1,1,0,1,1,1,1,1,\
1,1,1,1,0,0,0,1,1,1,\
1,1,1,1,0,0,0,1,1,1,\
1,1,1,0,0,0,0,1,1,1,\
1,1,1,0,0,0,0,1,1,1,\
1,1,1,0,0,0,0,1,1,1,\
1,1,1,1,0,0,0,1,1,1,\
1,1,1,1,1,0,1,1,1,1,\
1,1,1,1,1,1,1,1,1,1
};
int main()
{
int i;
int j;
int x = 10;
int y = 10;
int width;
int height;
char *pstart,*pend;
char *p = malloc(x * y);
if(p == NULL)
{
printf("malloc failed\n");
return -1;
}
for(i = 0; i < x; i++)
{
for(j=0;j<y;j++)
{
if(a[i][j] == 1)
*(p+i*y+j) = 0x31;
else
*(p+i*y+j) = 0x30;
}
}
pstart = p + (x-1)/2 * y ;
pstart = strstr(pstart,"111000");
if(pstart == NULL)
return -1;
pstart = pstart + 3;
pend = strstr(pstart,"000111");
if(pend == NULL)
return -1;
pend = pend + 3;
width = pend - pstart;
printf("width:%d\n",width);
char *pp = malloc(x * y);
if(pp == NULL)
{
printf("malloc failed\n");
return -1;
}
for (i = 0; i< x; i++)
{
for(j = 0; j< y; j++)
{
*(pp + i * x + j) = *(p + j * y + i);
}
}
for (i = 0; i< x; i++)
{
for(j = 0; j < y; j++)
{
printf("%c ", *(pp + i * x + j));
}
printf("\n");
}
pstart = pp + (y-1)/2 * x ;
pstart = strstr(pstart,"1000");
if(pstart == NULL)
return -1;
pstart = pstart + 1;
pend = strstr(pstart,"0001");
if(pend == NULL)
return -1;
pend = pend + 3;
height = pend - pstart;
printf("height:%d\n", height);
return 0;
}