#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define MAX_ROWS 10
#define MAX_COLS 10
static char map[10][10];
void sin1(char map[][MAX_COLS]);
void sin2(void);
void sin3(char map[][MAX_COLS]);
int main(void)
{
system("chcp 1253 >nul ");
FILE *fileptr;
char myColchar,apantisi,map[MAX_ROWS][MAX_COLS];
int metritis1=0,apotelesma,myColnum=1,myrow=1,k,a,l,c,row, col;
char r,fileRow[MAX_COLS + 2]; // account for newline and NULL
printf("dose tin diataksi me ton arithmo pou epithymeis(1/2): \n");
scanf("%d",&k);//edo tha iparxei sinartisi pou tha pairnei to k os parametro kai tha exei void epistrofi...
while (k!=1 && k!=2){
printf("ekanes lathos dose ksana tin diataksi me ton arithmo pou epithymeis(1/2): \n");
scanf("%d",&k);}
if (k==1){
fileptr = fopen("1.txt", "r");}
else if (k==2){
fileptr=fopen("2.txt","r");}
else {
printf("de dosate sosto\n");}
if (fileptr == NULL)
{
perror("File Open Error");
return -1;
}
else if (fileptr!=NULL){
printf(" A B C D E F G H I J\n");
printf("--------------------- \n");
for (row = 0; row < MAX_ROWS; row++)
{
fgets(fileRow, sizeof(fileRow), fileptr);
printf("|");
for (col = 0; col < MAX_COLS; col++){
map[row][col] = fileRow[col];
if (map[row][col]=='.'){
map[row][col]=' ';}
printf("%c",map[row][col]);
printf("|");}
printf("%d",row+1);
printf("\n");
printf("--------------------- \n");
}}
printf("\nse periptosi pou ekteleite voli patiste <<N>> allios <<O>>: \n");
printf("Ektelesi Volis (N/O): \n");
scanf("%s",&apantisi);
if (apantisi=='N'){
sin2();
}
else if (apantisi=='O'){
sin3(map);
sin1(map);
}
fclose(fileptr);
system("pause");
// now you have the map loaded,
// so do the rest of your program
return 0;
}
//*****************************************************************************************************************************
void sin1(char map[][MAX_COLS])
{
int row,col;
for (row = 0; row < MAX_ROWS; row++)
{
printf("|");
for (col = 0; col < MAX_COLS; col++){
printf("%c",map[row][col]);
printf("|");}
printf("%d",row+1);
printf("\n");
printf("--------------------- \n");
}
}
// *************************************************************************************************************************
void sin2(void)
{
int metritis1=0,l,c,apotelesma;
srand ( time(NULL) );
l = rand() % 10;
c = rand() % 10;
c=65+c;
l=l+1;
printf("Katastasi: Ektelesi Volis\n");
printf("sintetagmenes ekserxomenis volis: %c%d\n",c,l);
printf("Apotelesma ektelestheisas volis(Patiste <<1>> gia eystoxi kai <<2>> gia astoxi)\n");
printf("Voli %c %d: \n",c,l);
scanf("%d",&apotelesma);
while (apotelesma!=1 && apotelesma!=2){
printf("Apotelesma ektelestheisas volis(Patiste <<1>> gia eystoxi kai <<2>> gia astoxi)\n");
printf("Voli %c %d: \n",c,l);
scanf("%d",&apotelesma);}
if (apotelesma==1){
metritis1++;
}
else if (apotelesma==2){
}
}
//****************************************************************************************************************************
void sin3(char map[][MAX_COLS])
{
char myColchar;
int myColnum,myrow,col,row;
printf("Katastasi: Lipsi Volis\n");
printf("Sintetagmenes eiserxomenis Volis: \n");
scanf("%s %d", &myColchar,&myrow);
myColnum = (int)myColchar;
if(myColnum >= 97){
myColnum = myColnum - 97;}
else if((myColnum >=65) && (myColnum <=90)){
myColnum = myColnum - 65;}
col = myColnum;
row = myrow - 1; // Need to compensate because array starts at 0.
if (map[row][col]==' '){
map[row][col]='X';
printf("Apotelesma eiserxomenis volis: Anepityxis\n"); }
else if (map[row][col]=='Ð'){
map[row][col]='ð';}
else if (map[row][col]=='Í'){
map[row][col]='í'; }
else if (map[row][col]=='Ê'){
map[row][col]='ê';}
else if (map[row][col]=='Ö'){
map[row][col]='ö';}
else if (map[row][col]=='Õ'){
map[row][col]='õ';}
if (map[row][col]!='X'){
printf("Apotelesma eiserxomenis volis: Epityxis\n");}
}
the compiler doesn't show any errors but if the user enters 1 and then O then the function sin3 has something that causes error window that says that the memory is not able to read....can u tell me what is wrong?i mean i tried it too many times but i cant see what is wrong...all i want is tha the sin3 function will determine whether or not there is a ship in the map[row][col] and then change the map[row][col] with another symbol...but also i want when the sin3 ends that the changes will be applied to the map array to use them later in the program....can u tranform my code?