I have a program to calculate area and perimeter of a polygon. It reads each line of a text file, each line has some coordinates, and with that coordinates it calculates the area and the perimeter of the polygn.

To check if the output of the program corresponds to the correct area and perimeter I have 2 char arrays, each array corresponds to the correct result of each line of the file. The result array is to store the result values.

Code:
char expected[] = "80.0036.00";  // area = 80.00 perimeter = 36.00
char expected1[] = "48.0032.00"; // area = 48.00 perimeter = 32.00
char result[] = "";              // its purpose is to store the result values
The file coordinates.txt has two lines for now, the calculation result of the first line corresponds to the expected[] and the result of the other line corresponds to the expected1[]:
2 10 12 10 12 2 2 2
4 8 16 8 16 4 4 4

Im getting a problem that is altough the correct result "80.0036.00" is icual to the expected result "80.0036.00" the comparison result is always "Arrays are different". The same happens to the other lines. I also tried with sprintf but get same issue.


Code:
while (fgets(line, sizeof (line), data)){
    xycount = 0;
    polygon_area = 0;
    a = *(triangle*)malloc(sizeof (triangle));
    memset(polygon_vertices, 0, sizeof (polygon_vertices));
    line[strlen(line) - 1] = 0;
    token = strtok(line, " ");
    while (token != NULL){
        xy = atof(token);
        token = strtok(NULL, " ");
        polygon_vertices[xycount++] = xy;
    }
    idx = 0;
    triangles = (xycount / 2) - 2;
    for (index = 2, idx = 0;idx < triangles;index += 2, ++idx){
        a.v1[x] = polygon_vertices[0];
        a.v1[y] = polygon_vertices[1];
        a.v2[x] = polygon_vertices[index + 0];
        a.v2[y] = polygon_vertices[index + 1];
        a.v3[x] = polygon_vertices[index + 2];
        a.v3[y] = polygon_vertices[index + 3];
        triangle_area = area(a);
        polygon_area += triangle_area;

    }
    printf("area=%.2f\t", polygon_area);
    perim = perimeter(polygon_vertices, xycount);
    printf("perimeter=%.2f\n", perim);

    result[xycount] = printf("%.2f", polygon_area);
    result[xycount] += printf("%.2f", perim);

    if(strcmp(expected, result) == 0) {
        printf("Arrays match.");
    }
    else{
        printf("Arrays different\n");
    };

}