[ create a new paste ] login | about

Link: http://codepad.org/MRPQjo6S    [ raw code | output | fork ]

C++, pasted on May 2:
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
using namespace std;
const int ROWS = 600;
const int COLS = 800;

int readmap(int map[][COLS], int & irow, int & icol, char filename[]);
int fill(int map[][COLS], int irow, int icol, int startx, int starty,
	int goalx, int goaly);
void descent(int map[][COLS], int irow, int icol, int startx, int starty,
	char filename[]);
void printmap(int map[][COLS], int irow, int icol, char filename[]);

int main(int argc, char* argv[])
{
	int x;
	char infilename[100];
	char outfilename[100];
	int icol, irow, startx, starty, goalx, goaly;	
	static int map[ROWS][COLS] = { 0 };
	//file opening/closing won't happen here
	cout << "Enter input filename: ";
	cin.getline(infilename, '\n');
	while (infilename[0] == '\n')
	{
		cout << "Enter input filename: ";
		cin.getline(infilename, '\n');
	}
	cout << "\nEnter output filename [optional]: ";
	cin.getline(outfilename, '\n');
	if (outfilename[0] != '\n')
	{
		char temp1[100] = {' '};
		int x = strlen(infilename);
		strncpy(temp1, infilename, x - 4);
		char temp2[20] = { "_path.ppm" };
		strcat(temp1, temp2);
		strcpy(outfilename, temp1);
	}
	irow = 404;
	icol = 404;
	cout << "potato" << endl;
	x = readmap( map, irow, icol, infilename);
	cout << "tomato"<< endl;
	cout << "Please enter the start coordinates, x y: ";
	cin >> startx >> starty;
	cout << "Please enter the goal coordinates, x y: ";
	cin >> goalx >> goaly;
	fill (map, irow, icol, startx, starty, goalx, goaly);
	
}

int readmap(int map[][COLS], int &irow, int &icol, char filename[])
{
	int temp;
	int tmp;
	char temp1[1000];
	char temp2[1000] = { ".ppm" };
	int pixel[600][800][3] = { 0 };
	cout << "potator" << endl;
	ifstream fin;
	fin.open(filename);
	if (!fin)
	{
		cout << "File not found";
		return NULL;
	}
	temp = strlen(filename);
	strncpy(temp1, filename, temp - 4);
	strcat(temp1, temp2);
	tmp = strcmp(temp1, filename);
	if (tmp != 0)
	{
		cout << "File not PPM format";
		return NULL;
	}

	char color;
	int colornum;
	fin >> color;
	fin >> icol;
	fin >> irow;
	fin >> colornum;
	if (icol > 800 && irow > 600)
	{
		cout << "File too large";
		return NULL;
	}
	cout << "Image size: cols = " << icol << ",   rows= " << irow << endl;

	int p, r;

	for (p = 0; p < irow; p++)
	{
		for (r = 0; r < icol; r++)
		{
			fin >> pixel[p][r][0];
			fin >> pixel[p][r][1];
			fin >> pixel[p][r][2];

			if (pixel[p][r][0] > 127 || pixel[p][r][1] > 127 || pixel[p][r][2] > 127)
			{
				map[p][r] = -1;
			}
		}
	}

	return 1;

	
}

int fill(int map[][COLS], int irow, int icol, int startx, int starty,
	int goalx, int goaly)
{
	bool check = true;
	int count = 0;
	int i, j, g, h;
	map[goalx][goaly] = 1;
	while (map[startx][starty] == 0)
	{
		check = false;
		count++;
		while (check == false)
		{
				for (i = 0; i < irow; i++)
			{
				for (j = 0; j < icol; j++)
				{
					if (map[i][j] == count)
					{
						for (g = -1; g <= 1; g++)
						{
							for (h = -1; h <= 1; h++)
							{
								if (map[i + g][j + h] != -1 && g != 0 || h != 0)
								{
									if (map[i + g][j + h] == 0)
									{
										map[i + g][j + h] = count + 1;
									}
								}
							}
						}
					}
					else
						check = true;
				}
			}

		}
	}
	return 1;
}

void descent(int map[][COLS], int irow, int icol, int startx, int starty,
	char filename[])
{
	 
}

void printmap(int map[][COLS], int irow, int icol, char filename[])
{

}


Output:
1
2
3
4
5
6
7
8
9
cc1plus: warnings being treated as errors
In function 'int main(int, char**)':
Line 21: warning: missing braces around initializer for 'int [800]'
In function 'int readmap(int (*)[800], int&, int&, char*)':
Line 60: warning: missing braces around initializer for 'int [800][3]'
Line 60: warning: missing braces around initializer for 'int [3]'
Line 67: warning: converting to non-pointer type 'int' from NULL
Line 76: warning: converting to non-pointer type 'int' from NULL
Line 88: warning: converting to non-pointer type 'int' from NULL


Create a new paste based on this one


Comments: