Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Functional Programming in C Functions

How to call another function within int main and why it does not work

#include <stdio.h>
int inst;
int play;
int Xs[] = {0,0,0,0,0,0,0,0,0};
int Os[] = {0,0,0,0,0,0,0,0,0};
int Xplay(){
    printf("\%d |%d |%d\n__|__|__\n%d |%d |%d\n__|__|__\n%d |%d | %d\n  |  |\n");
    printf("Type which number you want to occupy");
    scanf("%d", &play);
    Xs[play] = 1;
    if (Xs[play] = 1){

    }
    return 0;
}
int main()
{
    printf("Welcome to Tic-Tac-Toe Text edition!\nPlease type anything to continue the instructions.\n");
        scanf("%d", &inst);
    printf("In order to play, you must enter a number for what square you wish to occupy.\n1 |2 |3\n__|__|__\n4 |5 |6\n__|__|__\n7 |8 | 9\n  |  |\n");
    printf("Please type anything to continue the instructions.\n\n");
        scanf("%d", &inst);
    printf("As you saw above, the numbers each symbolize a place where you can put your X or O. In order to do so, all you have to do is type the number in which you want to put your X or O\n\n");
    printf("Please type anything to continue the instructions.\n\n");
        scanf("%d", &inst);
    printf("That is all you need to know to play!\nType anything to play!\n");
        scanf("%d", &inst);
Xplay();
    return 0;
}

What are the problems with this code? Why can I NOT call the function Xplay? When I try to run it it just ignores the function completely. Someone help? I'm trying to make a simple tic- tac-toe game.

1 Answer

It's probably not being executed because it's not a properly structured conditional. Try adding another "=" to that "if" statement in your function.

nope

Could you provide more information? I don't think your reply is helping me, you or anyone else much in getting you towards the results you're looking for. What's the compiler saying? Is there an error? Is it doing nothing at all?

Actually I'm a little confused as to what you are trying to achieve in your code now that I look at it. What's going on here and what is it that you're wanting to do?

I want to make a simple text tic tac toe game. I want to call another function within my main module. When I run it, everything goes well until I hit the Xplay(); then it just does not even show the printf statement at all in the output. I need to figure out how to resolve that.