Skip to content

Instantly share code, notes, and snippets.

@rhysforyou
Forked from anonymous/function.cpp
Created May 14, 2012 10:59
Show Gist options
  • Select an option

  • Save rhysforyou/2693307 to your computer and use it in GitHub Desktop.

Select an option

Save rhysforyou/2693307 to your computer and use it in GitHub Desktop.
diff --git a/functions.cpp b/functions.cpp
index 7c53868..a4cb553 100644
--- a/functions.cpp
+++ b/functions.cpp
@@ -1,10 +1,10 @@
-#include "functions.h"
+#include "function.h"
#include <fstream>
using namespace std;
-bool loadmap ( int startpos[] , int gamemap[ROWS][COLUMNS])
+bool loadmap ( int startpos[] , int gamemap[ROWS][COLUM+1])
{
ifstream ins;
@@ -16,11 +16,11 @@ bool loadmap ( int startpos[] , int gamemap[ROWS][COLUMNS])
ins >> startpos[0] >> startpos[1];
for( int i = 0; i < ROWS; i++)
- { for ( int j= 0; j < COLUMNS; j++)
+ { for ( int j= 0; j < COLUM; j++);
ins >> gamemap[i][j];
}
// load map.txt into array
}
return 0;
-}
+}
\ No newline at end of file
diff --git a/functions.h b/functions.h
index 555c03a..443e364 100644
--- a/functions.h
+++ b/functions.h
@@ -1,6 +1,6 @@
#include <fstream>
const int ROWS= 10;
-const int COLUMNS= 10;
+const int COLUM= 10;
-bool loadmap ( int [] , int [ROWS][COLUMNS]);
+bool loadmap ( int [] , int [ROWS][COLUM+1]);
\ No newline at end of file
diff --git a/main.cpp b/main.cpp
index 7c15758..0acacb5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,12 +1,12 @@
#include <iostream>
-#include "functions.h"
+#include "function.h"
using namespace std;
int main ()
{
int startpos[2];
- int gamemap[ROWS][COLUMNS]= {{0}};
+ int gamemap[ROWS][COLUM+1]= {{0}};
@@ -16,12 +16,11 @@ int main ()
}
else
{
- for ( int i= 0; i < 10; i++)
- { for( int j= 0; j < 10; j++)
- cout << gamemap[i][j] << ", ";
- cout << endl;
+ for ( int i= 0; i < 11; i++)
+ { for( int j= 0; j < 11; j++)
+ cout << gamemap[i][j];
}
}
return 0;
-}
+}
\ No newline at end of file
#include "functions.h"
#include <fstream>
using namespace std;
bool loadmap ( int startpos[] , int gamemap[ROWS][COLUMNS])
{
ifstream ins;
ins.open("map.txt");
if(ins.fail())
return false;
else
{
ins >> startpos[0] >> startpos[1];
for( int i = 0; i < ROWS; i++)
{ for ( int j= 0; j < COLUMNS; j++)
ins >> gamemap[i][j];
}
// load map.txt into array
}
return 0;
}
#include <fstream>
const int ROWS= 10;
const int COLUMNS= 10;
bool loadmap ( int [] , int [ROWS][COLUMNS]);
#include <iostream>
#include "functions.h"
using namespace std;
int main ()
{
int startpos[2];
int gamemap[ROWS][COLUMNS]= {{0}};
if(loadmap( startpos,gamemap))
{
// play the game
}
else
{
for ( int i= 0; i < 10; i++)
{ for( int j= 0; j < 10; j++)
cout << gamemap[i][j] << ", ";
cout << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment