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

What are the differences between C and CPP?
What are the differences between C and CPP? Q: Is C++ a superset of C? What are the differences between C and C++? Can I use a C++ compiler to compile C code? A: C++ was derived from C, and is largely based on it, but there are some legal C constructs which are not legal C++. Conversely, ANSI C inhe...
2015-01-10, 1167👍, 0💬

I have a program that seems to run correctly
I have a program that seems to run correctly, but it crashes as it's exiting, after the last statement in main(). What could be causing this? A:There are at least three things to look for: 1. If a semicolon in a previous declaration is missing, main might be inadvertently declared as returning a str...
2015-05-29, 1166👍, 0💬

How can I make it pause before closing the program output window?
I'm compiling some test programs on a windows-based system, and the windows containing my program's output are closing so quickly after my program calls exit that I can't see the output. How can I make it pause before closing? After wondering why the author of your compiler's run-time system didn't ...
2015-04-24, 1166👍, 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, 1166👍, 0💬

I have got this tricky preprocessing I want to do and I cant figure out a way to do it.
I have got this tricky preprocessing I want to do and I cant figure out a way to do it. C's preprocessor is not intended as a general-purpose tool. (Note also that it is not guaranteed to be available as a separate program.) Rather than forcing it to do something inappropriate, you might want to wri...
2016-01-19, 1165👍, 0💬

How can I return a sequence of random numbers which dont repeat at all?
How can I return a sequence of random numbers which dont repeat at all? What you're looking for is often called a ``random permutation'' or ``shuffle.'' One way is to initialize an array with the values to be shuffled, then randomly interchange each of the cells with another one later in the array: ...
2015-07-24, 1165👍, 0💬

I keep getting errors due to library functions being undefined, but I am including all the right header files.
I keep getting errors due to library functions being undefined, but I am including all the right header files. In the general case of calling code in an external library, using #include to pull in the right header file(s) is only half of the story; you also have to tell the linker to search the exte...
2015-07-14, 1165👍, 0💬

My compiler is complaining that printf is undefined ...
My compiler is complaining that printf is undefined! How can this be? It's the world's most popular C function... Allegedly, there are C compilers for Microsoft Windows which do n ot support printf, on the argument that printf is for printing to old-fashioned terminals, while under Windows the right...
2015-07-03, 1165👍, 0💬

Why is my simple program, which hardly does more than print
Why is my simple program, which hardly does more than print ``Hello, world!'' in a window, compiling to such a huge executable (several hundred K)? Should I #include fewer header files? What you're seeing is the current (poor) state of the ``art'' in library design. As run-time libraries accrete mor...
2015-07-06, 1164👍, 0💬

Why does this code crash?
Why does this code: char *p = "hello, world!"; p[0] = 'H'; crash? String constants are in fact constant. The compiler may place them in nonwritable storage, and it is therefore not safe to modify them. When you need writable strings, you must allocate writable memory for them, either by declaring an...
2015-05-27, 1164👍, 0💬

I am splitting up a program into multiple source files for the first time ...
I'm splitting up a program into multiple source files for the first time, and I'm wondering what to put in .c files and what to put in .h files. (What does ``.h'' mean, anyway?) As a general rule, you should put these things in header (.h) files: macro definitions (preprocessor #defines) structure, ...
2016-02-18, 1163👍, 0💬

How can I generate random numbers with a normal or Gaussian distribution?
How can I generate random numbers with a normal or Gaussian distribution? There are a number of ways of doing this. 1. Exploit the Central Limit Theorem (``law of large numbers'') and add up several uniformly-distributed random numbers: #include &lt;stdlib.h> #include &lt;math.h> #define NSU...
2015-07-22, 1163👍, 0💬

I heard that you have to include stdio.h before calling printf. Why?
I heard that you have to include stdio.h before calling printf. Why? So that a proper prototype for printf will be in scope. A compiler may use a different calling sequence for functions which accept variable-length argument lists. (It might do so if calls using variable-length argument lists were l...
2015-06-17, 1162👍, 0💬

How can I implement a delay, or time a users response, with sub-second resolution?
How can I implement a delay, or time a users response, with sub-second resolution? Unfortunately, there is no portable way. Routines you might look for on your system include clock, delay, ftime, gettimeofday, msleep, nap, napms, nanosleep, setitimer, sleep, Sleep, times, and usleep. (A function cal...
2015-03-06, 1162👍, 0💬

What is the difference between const char .....
What's the difference between const char *p, char const *p, and char * const p? The first two are interchangeable; they declare a pointer to a constant character (you can't change any pointed-to characters). char * const p declares a constant pointer to a (variable) character (i.e. you can't change ...
2016-01-06, 1161👍, 0💬

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, 1161👍, 0💬

How can I send mail from within a C program?
How can I send mail from within a C program? Under Unix, open a pipe to the mail program, or perhaps /usr/lib/sendmail.
2015-04-17, 1160👍, 0💬

What are the complete rules for header file searching?
What are the complete rules for header file searching? The exact behavior is implementation-defined (which means that it is supposed to be documented; Typically, headers named with &lt;> syntax are searched for in one or more standard places. Header files named with "" syntax are first searched ...
2016-02-12, 1157👍, 0💬

Since array references decay into pointers ...
Since array references decay into pointers, if arr is an array, what's the difference between arr and &arr? The type. In Standard C, &arr yields a pointer, of type pointer-to-array-of-T, to the entire array. (In pre-ANSI C, the & in &arr generally elicited a warning, and was generall...
2015-12-09, 1157👍, 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, 1157👍, 0💬

I heard that you have to include ......
I heard that you have to #include before calling printf. Why? So that a proper prototype for printf will be in scope. A compiler may use a different calling sequence for functions which accept variable-length argument lists. (It might do so if calls using variable-length argument lists were less eff...
2016-01-08, 1156👍, 0💬

Why doesnt this code work?
Why doesn't this code: double d; scanf("%f", &amp;d); work? Unlike printf, scanf uses %lf for values of type double, and %f for float.%f tells scanf to expect a pointer-to-float, not the pointer-to-double you gave it. Either use %lf, or declare the receiving variable as a float.
2015-10-30, 1154👍, 0💬

Why isnt my procedure call working? The compiler seems to skip right over it
Why isnt my procedure call working? The compiler seems to skip right over it Does the code look like this? myprocedure; C has only functions, and function calls always require parenthesized argument lists, even if empty. Use myprocedure(); Without the parentheses, the reference to the function name ...
2015-06-01, 1154👍, 0💬

Why do some people write if(0 == x) instead of if(x == 0)?
Why do some people write if(0 == x) instead of if(x == 0)? It's a trick to guard against the common error of writing if(x = 0) If you're in the habit of writing the constant before the ==, the compiler will complain if you accidentally type if(0 = x) Evidently it can be easier for some people to rem...
2015-05-15, 1154👍, 0💬

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