I want to ask that in c programming we open a file using pointer by using how many pointer at the same time we can open the same file with out getting any error? Is there a limit? Also does sequence matter like
f1= fopen("abc.txt",r)
f2= fopen("abc.txt",w)
do f2 be close first or f1 can be close first too
Yes, most standard libraries impose some limit on how many files a particular process can have open at a time. As long as you’re halfway reasonable about things, however, and only open files as you need them, and close them when you’re done, it’s rarely an issue.
You’re guaranteed that you can open at least
FOPEN_MAXfiles simultaneously. In some cases you can open more than that, but (absent limits imposed elsewhere, such as the OS being short of resources) you can open that many.Edit: As to why you can often open many more files than
FOPEN_MAXindicates: it’s pretty simple: to guarantee the ability to open N files, you pretty much need to pre-allocate all the space you’re going to use for those files (e.g., a buffer for each). Since most programs never open more than a few files at a time anyway, they try to keep that number fairly low to keep from wasting too much memory on space most don’t use anyway.Then, to accommodate programs that need to open more files, they can/will use realloc (or something similar) to try to allocate more space as needed. Since realloc can fail, though, the attempt at opening more files can also fail.