samedi 25 juin 2016

Function returning nothing when it should return char

In the program I'm writing I have a class called Map and within that class is a function called coord, which returns the map coordinate of the given point.

Map class definition:

public class Map
{
    public static char map[][] = new char[150][150];

    public static char coord(Point locat)
    {
            if ((locat.v <= 0) || (locat.h <= 0))
                    return 'u0000';
            return map[locat.v-1][locat.h-1];
    }

    public static int readToArray(String filePath)
    {
            try (InputStream in = new FileInputStream(filePath);
                 BufferedReader from = new BufferedReader(new InputStreamReader(in))) {
                    int c, h, v;
                    h = v = 0;

                    while ((c = from.read()) != -1) {
                        if (c == 'n') {
                            v++;
                            h = 0;
                        } else {
                            map[v][h++] = (char) c;
                        }
                    }

                    in.close();
                    return v;

             } catch (IOException x) {
                    System.err.println(x);
             }
             return -1;
    }
    /* blah blah blah */
}

Point class definition:

public class Point
{
    public int h, v;
    /* blah blah blah */
}

The Map class is static. My main function calls readToArray.

I added printfs to find that the coord function passes the error check but the char returned is empty. Why is this and what should I do to change it?

Aucun commentaire:

Enregistrer un commentaire