I have a following piece of code for writing to file:
Code:
#include "stdio.h"
#define MAXITEMS (10)
typedef struct{
int eItem; //Item id
int eDwnlditemsSt; //Item Download status
bool Dwnldreq; //Is download req
char pUrl[255]; //Download Url
char pathstored[255]; // path were it is stored
int offset; //offset for next based on item state
}tsClnItmsDetails;
tsClnItmsDetails ListOfItemsWrite[MAXITEMS];
//tsClnItmsDetails ListOfItemsRead[MAXITEMS];
FILE *fmineptr;
void WriteToFlash(FILE *fptr)
{
//Can this be done:
for(int i = 0; i<MAXITEMS; i++)
{
fwrite(ListOfItemsWrite[i],1, sizeof(tsClnItmsDetails),fptr);
}
}
int main()
{
int i;
fmineptr = fopen("mine.txt","w+");
if(fmineptr == NULL)
printf("Error\n");
for(i=0;i<MAXITEMS;i++)
{
ListOfItemsWrite[i].Dwnldreq = 1;
ListOfItemsWrite[i].eDwnlditemsSt =2;
ListOfItemsWrite[i].eItem =3;
ListOfItemsWrite[i].offset=4;
ListOfItemsWrite[i].pathstored = "Some path";
ListOfItemsWrite[i].pUrl = "My path";
WriteToFlash(fmineptr);
}
fclose(fmineptr);
return 0;
}
Q:
1. I have errors while compiling:
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>d:\source\trystructread\trystructread\trystructr ead\trystructread.cpp(52) : error C2440: '=' : cannot convert from 'const char [10]' to 'char [255]'
1> There is no context in which this conversion is possible
1>d:\source\trystructread\trystructread\trystructr ead\trystructread.cpp(53) : error C2440: '=' : cannot convert from 'const char [8]' to 'char [255]'
2. I am have to write an entire structure to a File.