void writeFile()
{
const char * filePath = "numbers.txt";
int fd = open(filePath,O_RDWR);
int index,numAdd;
index = validIndex();
numAdd = validNumberToAdd();
void *addr = mmap(nullptr,1000,PROT_WRITE, MAP_SHARED| MAP_ANONYMOUS, fd,0);
char *p = (char *)addr;
p[index] = numAdd;
cout << "wrote " << numAdd << endl;
close(fd);
}
So I am able to read data in the numbers.txt when i manually put data into it. But when I try to write data using this function it will delete all the data in the file and leave it blank.
The intended function should be that I am able to open a file called numbers.txt pick an index and write a value from numAdd to the text file. Then when I close it and run again it will have the data stored into it.
rest of the code is on this pastebin not needed though but this writing function is my main problem. https://pastebin.com/UYfx6QdP