C++ not locating the file though absolute file location is given [EDIT: SOLVED]

Thread Starter

Vikram50517

Joined Jan 4, 2020
81
Iam writing a Cpp program to read the contents of a file. Iam doing this in my Redmi note 5 Pro Android 9 , oreo through Termux app [rooted].
The thing is it is not recognising my absolute path, but it is able to work with the files in my source code's directory , ~ is my root directory( in my case the home is root.) My Cpp file should be able to locate my file ~/sdcard/b.sh , but it is failing to do so, i wonder why?

This is my code:

Screenshot_2022-05-09-13-01-20-677_com.termux.jpg

After i run this in the terminal
Terminal:

Screenshot_2022-05-09-13-02-15-341_com.termux.jpg
 
Last edited:

Thread Starter

Vikram50517

Joined Jan 4, 2020
81
Last edited:

Thread Starter

Vikram50517

Joined Jan 4, 2020
81
That's a good question, i actually tried an alternative to locate the root directory '/' , but it still landed at the same result.
I tried, " '/'/sdcard. i included '/' instead of / to diffrentiate from the path slash and root slash

PS: Is there any other alternative way that i can try?
 
Last edited:

Thread Starter

Vikram50517

Joined Jan 4, 2020
81
where exactly? like i mean in which path should i create a new file? I tried creating a file in my root directory and it warns me that it is a read-only file system
 

MrSalts

Joined Apr 2, 2020
2,767
where exactly? like i mean in which path should i create a new file? I tried creating a file in my root directory and it warns me that it is a read-only file system
First of all, don't create files in root. Start by having the code print which user is running the code so you know which user you need to set the permission to allow writing.
second, try using command lines to do what you want to do to make sure it is even possible (create a directory in a particular directory). Try changing permissions (chmod) as needed and see if It works.
If nothing works and your Android system is locked down somehow, you'll need to somehow make a space that allows you to write from command lines before you bother writing code.
 
Top