Hellou. Can anyone tell me how can i save a string to a file?
I have this function:
void PrintGameBoard(jogo_4line*jg)
{
int i,n;
system("clear");
printf("===============Jogo do 4 em linha===============\n\n\n");
printf(" +--+--+--+--+--+--+--+\n");
for(i=1; i<=6; i++)
{
printf("%d |%c |%c |%c |%c |%c |%c |%c |\n",7-i,jg->T[i][1],jg->T[i][2],jg->T[i][3],jg->T[i][4],jg->T[i][5],jg->T[i][6],jg->T[i][7]);
if (i!=0) printf(" +--+--+--+--+--+--+--+\n");
}
printf(" ");
for (n=1;n<=7;n++) printf(" %d",n);
printf("\n");
}
i need to save the contents of this function to a file. I mean, this fucntion prints the state of a game 4 in a row in my program.
Then i have this function:
int SaveGame( jogo_4line *game, char *save1)
{
FILE *fp;
fp=fopen("save1","w");
char *str;
str=PrintGameBoard(game);
fprintf( fp,"%s\n", str);
fclose(fp);
return 1;
This is just a guess, obviously not working. Any clues on how to do this? thanks in advance