0
typedef struct
{
char name[64];
int balance;
int gain;
}
Player;
"%s\t%d\t%d\n", p.name, p.balance, p.gain ;

I'm trying to input this into my file and I'm wondering if there is any way that I could make that into one string so it will work with fputs();

count = 0;
    while ((fgets(buffer, BUFFER_SIZE, fp)) != NULL)
    {
        count++;

        /* If current line is line to replace */
        if (count == line)
            fputs("%s\t%d\t%d\n", p.name, p.balance, p.gain,fTemp);
        else
            fputs(buffer, fTemp);
    }
``` 
  • 5
    What's wrong with `fprintf`? – tadman May 05 '20 at 07:07
  • That is the format, that is now in the post, is what my friend and I are to use it to get it to update a specific line in a text file; however, when trying to use `fprintf()` it does not like that – John McCorkle May 05 '20 at 07:09
  • Code in comments just looks unreadable. Edit your question to include it there and you can apply formatting. – tadman May 05 '20 at 07:09
  • 1
    Hint: `fprintf` *not* `fputs`. – tadman May 05 '20 at 07:10
  • We just weren't updating balance itself in the function, so fprintf was working when we were using it just not updating. Thank you for saying that `fprintf` should work. – John McCorkle May 05 '20 at 07:26

0 Answers0