here is my code so far:

#include <stdio.h>
#include <string.h>

struct sale
{
  int week;
  int units;
  int price;
  char name[30];
};
       
int main(int argc, char *argv[])
{
  int week = 0;
  int units = 0;
  int price = 0;
  char name[30];
  int count = 13;
  int i = 0;
  struct sale weeklySale[13];
  int total = 0;

     for (i = 0; i < 13; i++)
     {
       scanf("%i %i %i %s", &weeklySale[i].week, &weeklySale[i].units,
&weeklySale[i].price, weeklySale[i].name);

      FILE *fp;

      fp = fopen("data.txt", "wb");
      if(fp == NULL)
      {
         printf("Sorry, there is no such file as data.txt");
      }

      fwrite(weeklySale[i].week, weeklySale[i].units, weeklySale[i].price, weeklySale[i].name, fp);

       fclose(fp) == 0? "succeeded" : "failed";


       if(weeklySale[i].week > 13)
       {
         break;
       }

     }

  return 0;
}

starting from the first for loop, i want to allow users to enter sales information for a period of 13 weeks, and store the sales values in a struct. once the values are in a struct, i want to store the struct values in a file called data.txt. (because data.txt will store all of the struct values whereas the struct will keep getting refreshed)..... then i want to close the "write mode" for the file and open the file in "read mode". once i have done that, i want to output the data in the form of week numbers and total sales in each week.

the problem in my code is that it wont let me write to the file, and the error messages i am getting are the following:

"In function main"
"warning: passing argument 1 of fwrite makes pointer from integer without a cast"
"warning passing argument 4 of fwrite from incompatible pointer type"
"too many arguments to function fwrite"

......does anyone have any idea of whats going wrong because i'm going to kill someone soon if i dont start making some sort of progress :angry: :yawn: (i've been doing this since yesterday - i know, its very bad!!)

The errors come from using the fwrite() function in an incorrect way.
Here's an usage example
Pay attention to its prototype.

check the format of the fwrite because you have written
incorrect format of fwrite()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.