in this structure i want to change the flag value to 1 ..i was try this code but does not work
#include <SPI.h>
File dataFile;
typedef struct book
{
char
void setup() {
WiFi.disconnect();
Serial.begin(9600);
Serial.print("Initializing SD card...");
while (!Serial);
bool ok = SPIFFS.begin();
Serial.println("card initialized.");
dataFile = SPIFFS.open("/testme.txt", "r");
delay(50);
// Serial.print( "flag==");
system
March 13, 2019, 12:25pm
2
dataFile.seek(51);
Where did you come up with this value? It's wrong.
that i write because title is 20 byte,author is 20 byte and pages 10 byte so totel 50 byte .after 50 byte , flag value can rewrite ..
may be this logic is not good ..could you please give some modification in my code
system
March 13, 2019, 1:27pm
4
that i write because title is 20 byte,author is 20 byte and pages 10 byte
Wrong. pages is an int, and an int is TWO bytes.
that right sir..any other area i want to modify ?
system
March 13, 2019, 1:37pm
6
wounder:
that right sir..any other area i want to modify ?
Any other that cause incorrect results. I don't know what changes you have made, or what the results of those changes were.
dataFile.seek(51); changed into dataFile.seek(62);
but while printing flag value it still showing zero
system
March 13, 2019, 1:56pm
8
dataFile.seek(51); changed into dataFile.seek(62);
Explain how 20 + 20 + 20 + 1 equals 62.
You REALLY should read an entire struct, change the struct values, and re-write the entire struct. You do not know how much padding, if any, is in the struct
yes ..thats was my mistake ..
but after change it still showing flag=0
In your first code you are writing to the second structure, but you read from the first.
dataFile.seek(62);
dataFile.write(&flagme, sizeof(flagme));
dataFile.seek(0);
dataFile.read((uint8_t *)&b1, sizeof(b1));
BTW You should not make changes to older posts, like the changing of the offset.
If you make changes to your code, you should post the new version you are working with in a new post.
system
March 13, 2019, 5:29pm
11
dataFile = SPIFFS.open("/testme.txt", "r");
delay(50);
Book b1;
dataFile.seek(60);
dataFile.write(&flagme, sizeof(flagme));
dataFile.read((uint8_t *)&b1, sizeof(b1));
Doesn't it matter whether you were able to open the file? It would to me.
Now, you need to explain how 20 + 20 + 20 + 1 equals 60.
Writing to the file advances the cursor. Does reading 62 bytes after writing 2 bytes make sense?
Have you confirmed that sizeof(b1) IS 62?
sorry writing error ..yes its 61
@wounder , please do not cross-post. Threads merged.