First, learn the value of indentation -> SourceForge.net: Indentation - cpwiki
You can spot many kinds of bugs very easily just by indenting properly and consistently. For example, you would ask why there is a return statement at line 154 INSIDE the while loop!.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int sira;
int stili;
int A[9][3];
char answer;
int oles_piasmenes;
int e_sinartisi(int A[9][3], int sira, int stili);
int k_sinartisi(int A[9][3], int oles_piasmenes);
int main(void)
{
answer = 'a';
sira = 0;
stili = 0;
oles_piasmenes = 0;
while (sira <= 9) {
while (stili <= 3) {
A[sira][stili] = 0;
stili++;
}
stili = 0;
sira++;
}
while (answer != 'Q' && oles_piasmenes != 1) {
system("pause");
system("cls");
printf("Parakalo pliktrologiste E gia <<Emfanisi thesewn>>.\n");
printf("Parakalo pliktrologiste K gia <<Kratisi thesewn>>.\n");
printf("Parakalo pliktrologiste Q gia eksodo apo to programma.\n");
scanf("%c\n", answer); //!! not scanf_s
if (answer != 'E' && answer != 'K' && answer != 'Q') {
printf("Prosoxi pliktrologisate lathos apantisi.\n");
printf("\nH apantisi prepei na einai me kefalaia kai agglika!\n");
system("sleep 4");
}
if (answer == 'E') {
sira = 0;
stili = 0;
// int e_sinartisi(A[9][3]);
// int sira;
// int stili;
sira = 0;
stili = 0;
}
if (answer == 'K') {
int k_sinartisi(int A[9][3], int oles_piasmenes);
}
}
if (oles_piasmenes == 1) {
system("pause");
printf("Oles oi theseis einai piasmenes!\n");
system("cls");
}
return 0;
}
int e_sinartisi(int A[9][3], int sira, int stili)
{
stili = 0;
sira = 0;
while (sira <= 9) {
while (stili <= 3) {
if (A[sira][stili] == 0) {
if (sira == 0) {
sira = sira + 1;
printf("H thesi A%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 1) {
sira = sira + 1;
printf("H thesi B%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 2) {
sira = sira + 1;
printf("H thesi C%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 3) {
sira = sira + 1;
printf("H thesi D%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 4) {
sira = sira + 1;
printf("H thesi E%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 5) {
sira = sira + 1;
printf("H thesi F%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 6) {
sira = sira + 1;
printf("H thesi G%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 7) {
sira = sira + 1;
printf("H thesi H%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 8) {
sira = sira + 1;
printf("H thesi I%d einai kaini.\n", sira);
sira = sira - 1;
}
if (sira == 9) {
sira = sira + 1;
printf("H thesi J%d einai kaini.\n", sira);
sira = sira - 1;
}
}
stili++;
}
stili = 0;
sira++;
}
}
int k_sinartisi(int A[9][3], int oles_piasmenes)
{
int x;
int m;
int xsir;
int xst;
x = 0;
printf("Parakalo pliktrologiste ton arithmo theseon gia kratisi.\n");
scanf("%d\n", x); //!! not scanf_s
m = 1;
while (m <= x) {
system("cls");
printf("Parakalo pliktrologiste ton arithmo siras kai stilis gia tin tsesi.\n");
printf("Prota ton arithmo siras, keno kai meta ton arithmo stilis, meta stin\n");
printf("epomeni epanalipsi to idio gia tin epomeni thesi.\n");
//!! int scanf_s(const char *_Format, xsir, xst);
if (A[xsir][xst] == 0) {
A[xsir][xst] = 1;
} else {
printf("Kanate lathos, i thesi pou epileksate einai piasmeni!\n");
system("pause");
system("cls");
printf("Tha ksanapliktrologisete tin thesi ayti!\n");
system("pause");
m--;
}
m++;
return 0;
}
}
Second, avoid microsoft's attempts to create a non-standard "safe" API by appending _s on the end of everything.
1. It's only safe if you know what you're doing.
2. If you know what you're doing, you may as well use the ANSI/ISO standard functions anyway.
All you succeed in doing is making it harder for other people to help you (if they're not ms users).
Finally, some issues to fix.
Code:
$ gcc -Wall foo.c
foo.c: In function ‘main’:
foo.c:34: warning: format ‘%c’ expects type ‘char *’, but argument 2 has type ‘int’
foo.c: In function ‘k_sinartisi’:
foo.c:135: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
foo.c:156: warning: control reaches end of non-void function
foo.c: In function ‘e_sinartisi’:
foo.c:125: warning: control reaches end of non-void function
foo.c: In function ‘k_sinartisi’:
foo.c:143: warning: ‘xsir’ may be used uninitialized in this function
foo.c:143: warning: ‘xst’ may be used uninitialized in this function