![]() |
|
#1
|
|||
|
|||
standard I/O : fopen()hi,i want to ask bout fopen()in thecode :
CPP / C++ / C Code:
i want to ask bout fopen in the code prog.also i have read a review bout standard I/O include fopen.then i compare using fopen in that review n in the prog. prog: FILE *st; strcpy(fname,argv[parm]); st=fopen(fname,"rb"); if(st==NULL) ----- review: FILE *fptr; fptr = fopen("a:\\data\\customer.dat","w+"); if (fptr == NULL) ------ 1. what does the prog do with line :strcpy(fname,argv[parm]).since it is no path file can the prog open the file ? 2.i also read that if use "rb",the file must exist.so if the code doesn't use the path file ,i think the file doeesn't exist and the prog can't run.is it true? 2.is it any difference with the review & the prog,and if the both code can used which code is better? i am still confuse bout code in c++,so i'll thank for ur help . |
|
#2
|
|||
|
|||
|
Quote:
strcpy copies one string to another. So if argv[parm] contained "welcome" then strcpy (fname, argv[parm]) would set fname to "wlecome". (Although, I would strongly suggest using strncpy or strndup as they limit the number of characters you can copy) Quote:
Using "r", which is a request to read, requires that there is a file there to actually read from. Quote:
The only difference in the two is that in one you create a variable containing the text for fopen, and in the other you pass the text directly to fopen. Assuming that fname == "a:\\data\\customer.dat" there is no difference. Note, your program opens the file for "rb", the sample opens for "w+", THAT is different, but you can google for fopen to find more about it's flags |
|
#3
|
|||
|
|||
replyCPP / C++ / C Code:
i use trace info(f7) to know the steps in the prog.there are only 5 step as seen above and after i run the prog ,there is no output . why does the steps only 5 and i need help to make code so the prog have output |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| fopen fails to create a file pointer | gaoanyu | C++ Forum | 3 | 05-Jun-2005 11:16 |
| Definitions for Standard Library Functions? | BobbyMurcerFan | C++ Forum | 8 | 07-Jan-2005 10:45 |
| [Discussion][Tutorial] Standard I/O | Pandiani | C Programming Language | 1 | 09-May-2004 02:30 |
| [Tutorial] Standard I/O | aaroncohn | C Programming Language | 20 | 27-Feb-2004 21:07 |
| New wi-fi standard approved - here comes 24-54Mbps | jrobbio | Open Discussion Forum | 1 | 17-Jul-2003 00:29 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The