Quote:
Originally Posted by gamer99
Thanks a lot ... i will try it
One more thing if the file does not exits then how to wirte that file and make the first entry ?
for example
Code:
if(!file_exists(file))
{
file_handle = fopen(file, "wt")
//holder is the string
fputs(file_handle, holder)
fclose(file_handle)
}
is it a good way or there are some better way ?
|
For something this simple I would use what I posted. With write_file()\read_file(), you do not open and close a file, you simply call the function and it does all of the work for you. There is no need to check if file exists since when you call write_file(), it will create a new file if one doesnt exist and write the line for you. If you still want to check if the file exists for some other reason, just use the file_exists() native.
You can access various lines in the file if you need to. If you notice, there is a 0 parameter specified which relates to the first line in the file. If you replace that with 1 it will work with the second line in the file, and so on.
__________________