#include <stdio.h>
#include <stdlib.h>
#include <time.h>
	
main(){
char cChoice;

printf("****************************************\n\n");
printf("            FLIP!-TAC-TOE 3D            \n\n");
printf("       Enter S to start the game or     \n\n");
printf("               E to exit!               \n\n");
printf("               Choice: ", cChoice);
scanf("%c", &cChoice);
if(cChoice == 'S') function1 ();
else exit(EXIT_SUCCESS);
printf("\n****************************************\n\n");
system("CLS");

void function1(){
char cMarker1;
int i = 1; 
char alpha[] = "abcdefghijklmnopqrstuvwxyzW";
while (1)
{
printf("****************  TURN %d  ******************\n\n", i);
printf("    |     |        |     |        |     |     \n");
printf("  %c |  %c  | %c    %c |  %c  | %c    %c |  %c  | %c   \n", alpha[0], alpha[1], alpha[2], alpha[9], alpha[10], alpha[11], alpha[17], alpha[18], alpha[19]);
printf(" ___| ___ |___  ___| ___ |___  ___| ___ |___  \n");
printf("    |     |        |     |        |     |     \n");
printf("  %c |  %c  | %c    %c |  %c  | %c    %c |  %c  | %c   \n", alpha[3], alpha[4], alpha[5], alpha[12], alpha[26], alpha[13], alpha[20], alpha[21], alpha[22]);
printf(" ___| ___ |___  ___| ___ |___  ___| ___ |___  \n");
printf("    |     |        |     |        |     |     \n");
printf("  %c |  %c  | %c    %c |  %c  | %c    %c |  %c  | %c   \n", alpha[6], alpha[7], alpha[8], alpha[14], alpha[15], alpha[16], alpha[23], alpha[24], alpha[25]);
printf("    |     |        |     |        |     |     \n\n"); 
printf("Where would you want to place your \nmarker? ");
scanf("%c", &cMarker1);

if( cMarker1 >= 'a' && cMarker1 <= 'z' ){
fflush(stdin);
alpha[cMarker1-'a'] = 'X';
printf("You chose to place your marker on \nblock %c\n", cMarker1);
}
else{ 
printf("Cannot place your marker at %c\n", cMarker1);
printf("********************************************\n");
i++;
}

*How can I call the function1 in the main? so that when the user inputs S it will start the game.. Can somebody reconstruct my code? Thank you very much!

But you have already called it in the if loop! What's the problem?

But you have already called it in the if loop! What's the problem?

What's the problem?
1) Formatting is non-existent.
2) main() is wrong.
3) fflush(stdin) is undefined.
4) Using scanf to read a character -- see the entire scanf series for maximum info.

That's what I see.

What's the problem?
1) Formatting is non-existent.
2) main() is wrong.
3) fflush(stdin) is undefined.
4) Using scanf to read a character -- see the entire scanf series for maximum info.

That's what I see.

I think you misunderstood me!! He was asking how to call the function1,which he did,in the if loop and about the above said problems..
1.Yes formatting is not there,but that won't give any compilation errors,would it?
2.The return type is not mentioned in the main function but the default one ( void) will be taken up,as far as I know!
about the rest I agree!!

I think you misunderstood me!! He was asking how to call the function1,which he did,in the if loop and about the above said problems..

Didn't misunderstand anything. I know what he asked.

1.Yes formatting is not there,but that won't give any compilation errors,would it?

No in and of itself. But bad formatting very often hides error that are obvious if the formatting was done. And why should I spend 20 minutes trying to read his code when, with formatting, I could find the error in a minute or two.

2.The return type is not mentioned in the main function but the default one ( void) will be taken up,as far as I know!

Try reading the link.

A simple game might have pseudo code for a game loop, similar to this:

int main(void) {  
 char answer='y'

  while(answer == 'y') {
    prompting Do you want to play a game of ... ? [y/n]: 
    scanf("%c", &answer);  //get user's answer
    getchar();  //remove left over newline char from input buffer

    if answer == 'y'
      call play1game function
  }   
  print Goodbye
  return 0;
}

This is just to show some logic. It's not a program.

Good, consistent formatting, may not seem important yet, but over time, your eye/brain, will become trained to recognize many standard C idioms, and EASILY catch many errors in both syntax and logic. The more you program, the better your "eye" will become.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.