Heh.
I came to school and got my program to work, thankfully. (novacain, thanks for pointing out that == thing...I must be retarted or somethingOh, and yeah, its an assignment, though far from being done, as you can tell. I know what I want to do as far as the code goes, I went and wrote out a flow chart and everything, but I keep coming up with errors that I dunno how to deal with.) But now I've got a small problem with my function. Its almost the exact same code as before:
/*Include Statements*/
#include <stdio.h>
#include <string.h>
/*Data Structures*/
struct GAME
{
char location[3][3];
};
/*Function Prototypes*/
void displayboard(GAME pos);
void setblank(GAME positionfunct);
/*Main Function*/
int main(void)
{
/*Variable Declaration*/
GAME position;
/*Sets all of the Mark Locations to a Blank Space*/
setblank(position);
displayboard(position);
return 0;
}
void setblank(GAME positionfunct)
{
int a, b;
for(a=0; a<3; a++)
{
for(b=0; b<3; b++)
{
positionfunct.location[a][b] = ' ';
}
}
return;
}
void displayboard(GAME pos)
{
printf("\n\t\t\t Columns");
printf("\n\t\t\t 1 2 3\n");
printf("\n\t\t\t | |");
printf("\n\t\t\t 1 %c | %c | %c", pos.location[0][0], pos.location[1][0], pos.location[2][0]);
printf("\n\t\t\t | |");
printf("\n\t\t\tR =================");
printf("\n\t\t\to | |");
printf("\n\t\t\tw 2 %c | %c | %c", pos.location[0][1], pos.location[1][1], pos.location[2][1]);
printf("\n\t\t\ts | |");
printf("\n\t\t\t =================");
printf("\n\t\t\t | |");
printf("\n\t\t\t 3 %c | %c | %c", pos.location[0][2], pos.location[1][2], pos.location[2][2]);
printf("\n\t\t\t | |\n");
return;
}
...but now, like I said, I've got a problem with my function somewhere. The loop that I have in my setblank function to set all the positions to ' ' isn't working. If I take the loop out of the function and stick it into main, it works perfectly. But if I leave it in its function, it doesn't set the locations to a blank space, it sets it to this '¨d'. The only thing that I can think of, is that somewhere along the way, when I'm passing the variable from main to my function, its getting messed up. I know that arrays are passed by location by default, so I didn't think I'd need to use pointers. I went and tried it with pointers, thinking that maybe since it was a new variable type (GAME), it would require them. It just came up with a few errors, so I don't think that was it. I'd like to have the loops in their own function, though its really not needed, because I only use it once through every run. If you guys(and girls?) have any idea, please let me know, if not I'll just stick it into the main function and lose a point or two. ;p .
Thanks for your time,
- Pat



LinkBack URL
About LinkBacks
Oh, and yeah, its an assignment, though far from being done, as you can tell. I know what I want to do as far as the code goes, I went and wrote out a flow chart and everything, but I keep coming up with errors that I dunno how to deal with.) But now I've got a small problem with my function. Its almost the exact same code as before:


