How can I check whether a file exists? I want to warn the user if a requested input file is missing.
How can I check whether a file exists? I want to warn the user if a requested input file is missing. It's surprisingly difficult to make this determination reliably and portably. Any test you make can be invalidated if the file is created or deleted (i.e. by some other process) between the time you ... 2015-04-15, 1086👍, 0💬
How can I find out the size of a file, prior to reading it in?
How can I find out the size of a file, prior to reading it in? If the ``size of a file'' is the number of characters you'll be able to read from it in C (or which were written to it by a previous program), it can be difficult or impossible to determine this number exactly (other than by reading the ... 2015-04-15, 1072👍, 0💬
How can I find the modification date and time of a file?
How can I find the modification date and time of a file? The Unix and POSIX function is stat, which several other systems supply as well. 2015-04-13, 1080👍, 0💬
How can I insert or delete a line (or record) in the middle of a file?
How can I insert or delete a line (or record) in the middle of a file? In general, there is no way to do this. The usual solution is simply to rewrite the file. When you find yourself needing to insert data into an existing file, here are a few alternatives you can try: * Rearrange the data file so ... 2015-04-13, 1036👍, 0💬
How can I recover the file name given an open stream or file descriptor?
How can I recover the file name given an open stream or file descriptor? This problem is, in general, insoluble. Under Unix, for instance, a scan of the entire disk (perhaps involving special permissions) would theoretically be required, and would fail if the descriptor were connected to a pipe or r... 2015-04-10, 1169👍, 0💬
How can I delete a file?
How can I delete a file? The Standard C Library function is remove. (This is therefore one of the few questions in this section for which the answer is not ``It's system-dependent.'') On older, pre-ANSI Unix systems, remove may not exist, in which case you can try unlink. 2015-04-10, 999👍, 0💬
How do I copy files?
How do I copy files? Either use system() to invoke your operating system's copy utility, or open the source and destination files (using fopen or some lower-level file-opening system call), read characters or blocks of characters from the source file, and write them to the destination file. Here is ... 2015-04-08, 1121👍, 0💬
Why cant I open a file by its explicit path?
Why can't I open a file by its explicit path? The call fopen("c:\newdir\file.dat", "r") is failing. The file you actually requested--with the characters \n and \f in its name--probably doesn't exist, and isn't what you thought you were trying to open. In character constants and string literals, the ... 2015-04-08, 1102👍, 0💬
fopen isnt letting me open files like "$HOME/.profile" and "~/.myrcfile".
fopen isn't letting me open files like "$HOME/.profile" and "~/.myrcfile". Under Unix, at least, environment variables like $HOME, along with the home-directory notation involving the ~ character, are expanded by the shell, and there's no mechanism to perform these expansions automatically when you ... 2015-04-06, 1177👍, 0💬
How can I suppress the dreaded MS-DOS Abort, Retry, Ignore? message?
How can I suppress the dreaded MS-DOS Abort, Retry, Ignore? message? Among other things, you need to intercept the DOS Critical Error Interrupt, interrupt 24H. See the comp.os.msdos.programmer 2015-04-06, 1129👍, 0💬
How can I increase the allowable number of simultaneously open files?
I'm getting an error, ``Too many open files''. How can I increase the allowable number of simultaneously open files? A: There are typically at least two resource limitations on the number of simultaneously open files: the number of low-level ``file descriptors'' or ``file handles'' available in the ... 2015-04-03, 1137👍, 0💬
How can I find out how much free space is available on disk?
How can I find out how much free space is available on disk? There is no portable way. Under some versions of Unix you can call statfs. Under MS-DOS, use interrupt 0x21 subfunction 0x36, or perhaps a routine such as diskfree. Another possibility is to use popen to invoke and read the output of a ``d... 2015-04-03, 1036👍, 0💬
How can I read a directory in a C program?
How can I read a directory in a C program? See if you can use the opendir and readdir functions, which are part of the POSIX standard and are available on most Unix variants. Implementations also exist for MS-DOS, VMS, and other systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which do esse... 2015-04-01, 1130👍, 0💬
How do I create a directory? How do I remove a directory (and its contents)?
How do I create a directory? How do I remove a directory (and its contents)? If your operating system supports these services, they are likely to be provided in C via functions named mkdir and rmdir. Removing a directory's contents as well will require listing them and calling remove . If you don't ... 2015-04-01, 1097👍, 0💬
How can I find out how much memory is available?
How can I find out how much memory is available? Your operating system may provide a routine which returns this information, but it's quite system-dependent. (Also, the number may vary over time.) If you're trying to predict whether you'll be able to allocate a certain amount of memory, just try it-... 2015-03-30, 1162👍, 0💬
How can I allocate arrays or structures bigger than 64K?
How can I allocate arrays or structures bigger than 64K? A reasonable computer ought to give you transparent access to all available memory. If you're not so lucky, you'll either have to rethink your program's use of memory, or use various system-specific techniques. 64K is (still) a pretty big chun... 2015-03-30, 1112👍, 0💬
I thought that using large model meant that I could use more than 64K of data!
What does the error message ``DGROUP data allocation exceeds 64K'' mean, and what can I do about it? I thought that using large model meant that I could use more than 64K of data! Even in large memory models, MS-DOS compilers apparently toss certain data (strings, some initialized global or static v... 2015-03-20, 1072👍, 0💬
How can I do PEEK and POKE in C?
How can I access memory (a memory-mapped device, or graphics memory) located at a certain address? How can I do PEEK and POKE in C? Set a pointer, of the appropriate type, to the right number (using an explicit cast to assure the compiler that you really do intend this nonportable conversion): unsig... 2015-03-20, 1113👍, 0💬
How can I invoke another program (a standalone executable, or an operating system command) from within a C program?
How can I invoke another program (a standalone executable, or an operating system command) from within a C program? Use the library function system, which does exactly that. Some systems also provide a family of spawn routines which accomplish approximately the same thing. system is more ``portable'... 2015-03-18, 1137👍, 0💬
How can I call system when parameters (filenames, etc.) of the executed command arent known until run time?
How can I call system when parameters (filenames, etc.) of the executed command arent known until run time? Just use sprintf (or perhaps strcpy and strcat) to build the command string in a buffer, then call system with that buffer. (Make sure the buffer is allocated with enough space; Here is a cont... 2015-03-18, 1136👍, 0💬
How do I get an accurate error status return from system on MS-DOS?
How do I get an accurate error status return from system on MS-DOS? You can't; COMMAND.COM doesn't tend to provide one. If you don't need COMMAND.COM's services (i.e. if you're just trying to invoke a simple program, without I/O redirection and such) try one of the spawn routines, instead. 2015-03-16, 1142👍, 0💬
How can I invoke another program or command and trap its output?
How can I invoke another program or command and trap its output? Unix and some other systems provide a popen function, which sets up a stdio stream on a pipe connected to the process running a command, so that the calling program can read the output (or alternatively supply the input). Using popen, ... 2015-03-16, 1136👍, 0💬
How can my program discover the complete pathname to the executable from which it was invoked?
How can my program discover the complete pathname to the executable from which it was invoked? argv may contain all or part of the pathname, or it may contain nothing. You may be able to duplicate the command language interpreter's search path logic to locate the executable if the name in argv... 2015-03-13, 1108👍, 0💬
What is the difference between "printf(...)" and "sprintf(...)"? sprintf(...) writes data to the cha...
When does the compiler not implicitly generate the address of the first element of an array? Wheneve...
Are risk constant through out the project ? * Never say that risk is high through out the project. R...
How To Check the Oracle TNS Settings? - Oracle DBA FAQ - ODBC Drivers, DSN Configuration and ASP Con...
How To Calculate Expressions with SQL Statements? - MySQL FAQs - Introduction to SQL Basics There is...