File Input and Output, simple.
Hi, I want to know how to make a simple action in C.
Open a file and then write in the same line a simple thing:
first a char[30] thats means the name of a player and after 4 spaces or better a \t I need to write his scores.
How should I make this?
I tried to make a simple thing, but didnt worked.
Here is the code, my problems is writing the spaces and the score.. the name I writed perfectly
Code:
void saverecord(void)
{
FILE *fp; //The file...
//Open the file!
if((fp = fopen("scores.dat","a")) == NULL)
{
printf("Error! Cannot open the file!\n");
msleep(1); //Delay...
exit(1); //Exit...
}
//Write #HERE I NEED HELP#
fwrite(name, sizeof(name),1,fp);
//Now I havent any idea how to make the spaces and to
//output the number two...
//Close the file
fclose(fp);
}
Thanks for helping! ;)
I think you didnt understood what I want :)
I'll try to explain again.
I need to know how to write in a file something like this:
Joshua 100 Points
Now I got the 2 variables:
Name (char) and points (int)
I need to add on the file:
Name\tPoints
How do I make this, I know that I need to use fwrite, but I just know how to add the name not the \t and points :)
Thanks!
Re: I think you didnt understood what I want :)
Quote:
Originally posted by Vber
I'll try to explain again.
I need to know how to write in a file something like this:
Joshua 100 Points
Now I got the 2 variables:
Name (char) and points (int)
I need to add on the file:
Name\tPoints
How do I make this, I know that I need to use fwrite, but I just know how to add the name not the \t and points :)
Thanks!
Try actually reading this thread. Asked and answered. To quote Salem:
Quote:
fprintf( fp, "%s\t%d\n", name, score );
Quzah.