<< < 163 164 165 166 167 168 169 170 171 172 173 > >>   Sort: Date

Does C have anything like the `substr (extract substring) routine present in other languages?
Does C have anything like the `substr (extract substring) routine present in other languages? Not as such. To extract a substring of length LEN starting at index POS in a source string, use something like char dest[LEN+1]; strncpy(dest, &amp;source[POS], LEN); dest[LEN] = '\0'; /* ensure \0 term...
2015-08-19, 1161👍, 0💬

I mm compiling a program, and I seem to be missing one of the header files it requires
I mm compiling a program, and I seem to be missing one of the header files it requires There are several situations, depending on what sort of header file it is that's ``missing''. If the missing header file is truly a standard one (that is, one defined by the ANSI C Standard, such as &lt;stdio....
2016-02-05, 1160👍, 0💬

What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type?
What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type? Use a cast to convert the value to a known, conservatively-sized type, then use the printf format matching that type. For example, to print the size of a type, you might use printf("%lu...
2015-11-04, 1160👍, 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, 1160👍, 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, 1159👍, 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, 1159👍, 0💬

I am appalled that the ANSI Standard leaves so many issues undefined ...
I'm appalled that the ANSI Standard leaves so many issues undefined. Isn't a Standard's whole job to standardize these things? It has always been a characteristic of C that certain constructs behaved in whatever way a particular compiler or a particular piece of hardware chose to implement them. Thi...
2015-11-18, 1158👍, 0💬

What does it mean when the linker says that _end is undefined?
What does it mean when the linker says that _end is undefined? That message is a quirk of the old Unix linkers. You get an error about _end being undefined only when other symbols are undefined, too--fix the others, and the error about _end will disappear.
2015-07-06, 1158👍, 0💬

I am trying to do some simple trig...
I'm trying to do some simple trig, and I am #including &lt;math.h>, but the linker keeps complaining that functions like sin and cos are undefined. Make sure you're actually linking with the math library. For instance, due to a longstanding bug in Unix and Linux systems, you usually need to use ...
2015-07-01, 1158👍, 0💬

I need some code to do regular expression and wildcard matching.
I need some code to do regular expression and wildcard matching. Make sure you recognize the difference between: * Classic regular expressions, variants of which are used in such Unix utilities as ed and grep. In regular expressions, a dot . usually matches any single character, and the sequence .* ...
2015-08-12, 1156👍, 0💬

How can a process change an environment variable in its caller?
How can a process change an environment variable in its caller? It may or may not be possible to do so at all. Different operating systems implement global name/value functionality similar to the Unix environment in different ways. Whether the ``environment'' can be usefully altered by a running pro...
2015-03-11, 1156👍, 0💬

I am trying to sort an array of strings with qsort, using strcmp as the comparison function, but it is not working.
I am trying to sort an array of strings with qsort, using strcmp as the comparison function, but it is not working. By ``array of strings'' you probably mean ``array of pointers to char.'' The arguments to qsort's comparison function are pointers to the objects being sorted, in this case, pointers t...
2015-08-12, 1155👍, 0💬

I am trying to compile this program
I'm trying to compile this program, but the compiler is complaining that ``union REGS'' is undefined, and the linker is complaining that int86 is undefined. Those have to do with MS-DOS interrupt programming. They don't exist on other systems.
2015-03-02, 1154👍, 0💬

I am getting strange syntax errors inside lines I have ifdeffed out.
I am getting strange syntax errors inside lines I have ifdeffed out. Under ANSI C, the text inside a ``turned off'' #if, #ifdef, or #ifndef must still consist of ``valid preprocessing tokens.'' This means that the characters " and ' must each be paired just as in real C code, and the pairs mustn't c...
2015-12-14, 1153👍, 0💬

Where can I get an ANSI-compatible lint?
Where can I get an ANSI-compatible lint? Products called PC-Lint and FlexeLint are available from Gimpel Software. The Unix System V release 4 lint is ANSI-compatible, and is available separately (bundled with other C tools) from UNIX Support Labs or from System V resellers. Another ANSI-compatible ...
2015-05-05, 1153👍, 0💬

How can I tell how much destination buffer space ...
How can I tell how much destination buffer space I'll need for an arbitrary sprintf call? How can I avoid overflowing the destination buffer with sprintf? When the format string being used with sprintf is known and relatively simple, you can sometimes predict a buffer size in an ad-hoc way. If the f...
2015-10-19, 1152👍, 0💬

How can I return multiple values from a function?
How can I return multiple values from a function? There are several ways of doing this. (These examples show hypothetical polar-to-rectangular coordinate conversion functions, which must return both an x and a y coordinate.) 1. Pass pointers to several locations which the function can fill in: #incl...
2015-02-25, 1151👍, 0💬

This program crashes before it even runs!
This program crashes before it even runs! (When single-stepping with a debugger, it dies before the first statement in main.) You probably have one or more very large (kilobyte or more) local arrays. Many systems have fixed-size stacks, and even those which perform dynamic stack allocation automatic...
2015-05-29, 1149👍, 0💬

What is the ANSI C Standard?
What is the ANSI C Standard? In 1983, the American National Standards Institute (ANSI) commissioned a committee, X3J11, to standardize the C language. After a long, arduous process, including several widespread public reviews, the committee's work was finally ratified as ANS X3.159-1989 on December ...
2016-01-15, 1148👍, 0💬

If you cant modify string literals, why arent they defined as being arrays of const characters?
If you cant modify string literals, why arent they defined as being arrays of const characters? One reason is that so very much code contains lines like char *p = "Hello, world!"; which are not necessarily incorrect. These lines would suffer the diagnostic messages, but it's really any later attempt...
2016-01-06, 1148👍, 0💬

I am having trouble with a Turbo C program which crashes
I'm having trouble with a Turbo C program which crashes and says something like ``floating point formats not linked.'' Some compilers for small machines, including Turbo C (and Ritchie's original PDP-11 compiler), leave out certain floating point support if it looks like it will not be needed. In pa...
2015-06-19, 1148👍, 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[0] 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[0]...
2015-03-13, 1148👍, 0💬

How can I trap or ignore keyboard interrupts like control-C?
How can I trap or ignore keyboard interrupts like control-C? The basic step is to call signal, either as #include &lt;signal.h> signal(SIGINT, SIG_IGN); to ignore the interrupt signal, or as extern void func(int); signal(SIGINT, func); to cause control to transfer to function func on receipt of ...
2015-03-06, 1148👍, 0💬

My programs prompts and intermediate output dont always show up on the screen ...
My program's prompts and intermediate output don't always show up on the screen, especially when I pipe the output through another program. It's best to use an explicit fflush(stdout) whenever output should definitely be visible (and especially if the text does not end with \n). Several mechanisms a...
2015-11-11, 1147👍, 0💬

<< < 163 164 165 166 167 168 169 170 171 172 173 > >>   Sort: Date