Forum: C Jun 9th, 2009 |
| Replies: 18 Views: 883 A day ago csurfer's algorithm solved the problem. That's "pipelined" version:
int i, j = rand()%20;
for (i = 0; i < 20; i++)
array[i] = (i != j)*(rand()%9 + 1);
In addition:... |
Forum: C Jun 7th, 2009 |
| Replies: 7 Views: 606 All except '\r' and (may be) quotes ;)
Do you really want to study C i/o basics on DaniWeb forum?
Better search for a good C i/o tutorial. There are lots of good links... |
Forum: C Jun 1st, 2009 |
| Replies: 10 Views: 585 >c is generally slow compared to other programming language.
>Just out of curiosity, what languages should be faster?
Assembler, fortran?
Look at these wonderful benchmarks:... |
Forum: C May 26th, 2009 |
| Replies: 6 Views: 420 >Or do you know the 'ultimate' way?
Why not?
char* condense(char* s)
{
if (s) {
char* p = s;
char* q = s;
/* (never write so:) */
do if (*p != ' ') |
Forum: C May 25th, 2009 |
| Replies: 6 Views: 420 Remember KISS principle: no need in temporary strings! ;) |
Forum: C May 22nd, 2009 |
| Replies: 5 Views: 446 If you mean variable argument list, read this:
http://www.codeproject.com/KB/cpp/argfunctions.aspx?fid=15556&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=1066108 |
Forum: C May 20th, 2009 |
| Replies: 18 Views: 856 Impossible!
Can you prove it? How many bytes per second is OK? What's i/o channels capacity?
Even if it's true: serious applications are never discussed on the forums like DaniWeb. True crucial... |
Forum: C May 18th, 2009 |
| Replies: 18 Views: 856 /** Undestructive tokenizer.
@todo Add tsz < toksz test
*/
const char* getTok(const char* s, char* tok, int toksz, const char* delim)
{
if (s && *s) {
int dlen =... |
Forum: C May 8th, 2009 |
| Replies: 9 Views: 382 > guess i forgot about this particular epic battle...
It's not the echo of the epic battle, it's a regular untidiness ;)
See the language standard, for example: ...null character term used...
In... |
Forum: C May 7th, 2009 |
| Replies: 9 Views: 382 Please, don't forget: NULL is a ponter value in C. You (and me) can't terminate the string with a pointer ;) |
Forum: C Apr 28th, 2009 |
| Replies: 1 Views: 336 That's a nightmare... Is it a program in C? No, of course (see reinterpret_cast). But if it's a program in C++, where is operators new instead absolutely inadequate mallocs?!
I can't understand... |
Forum: C Apr 25th, 2009 |
| Replies: 5 Views: 614 >AND it with a bitmask 0x00FF to get the lower 16 bits...
It's one-byte mask... Where are 16 bits?..
>If bit 15 == 1, then OR all ones into bits 16-31 using the bitmask 0xFF00...
It's one-byte... |
Forum: C Apr 23rd, 2009 |
| Replies: 2 Views: 326 while("sMessage[x]"){
Why quotes?! ;)
It's a loop forever: while (pointer to string literal != 0). It never is null... |
Forum: C Apr 11th, 2009 |
| Replies: 2 Views: 264 1. Use code tag correctly:
source
2. Have you ever heard that all names must be declared before used in C? If not, take your textbook again. If yes, what's str (or str2) in strcat385 body?
... |
Forum: C Apr 3rd, 2009 |
| Replies: 2 Views: 274 Lines to be read: end - start + 1
Pointers allocated: end - start
Did you understand?
Use code tag with the language specifier!!!
sources |
Forum: C Feb 16th, 2009 |
| Replies: 4 Views: 663 Some melancholy remarks:
The most serious defect of strtok-based CSV parsing is that strtok skips null values. For example, in the line "1st,,3rd," strtok selects only two tokens: 1st and 3rd.
... |
Forum: C Dec 4th, 2008 |
| Replies: 2 Views: 719 K&R, chapter 5:
Where is "argv: pointer to char" in K&R? |
Forum: C Nov 24th, 2008 |
| Replies: 6 Views: 1,881 Probably but I'm here to give fishing-rods, not a fried fish ;) |
Forum: C Nov 23rd, 2008 |
| Replies: 5 Views: 2,028 Is it so hard job to correct obvious errors: you get compiler messages on wrong function arguments: fread and fwrite want POINTERS to target/source data areas (&d - not d, &b - not b))!
Use code... |
Forum: C Nov 8th, 2008 |
| Replies: 9 Views: 635 ddanbe, I'm indifferent to C#, Java, C++, Ada, Fortran, PL/I or what else codes on C forum for beginners. And shankhs? Let he/she gets the feel of new language (that's C)...
Best regards |
Forum: C Nov 8th, 2008 |
| Replies: 5 Views: 595 Look at the state-of-art programming of embedded systems for modern microcontrollers. As usually, all codes are written in C. Imagine: no any OS to support an execution of these programs (TinyOS,... |
Forum: C Nov 8th, 2008 |
| Replies: 9 Views: 635 I don't understand what for C# code appeares here. There are a lots of insertion (and others) sort C codes in INET. For example, that's one from the excellent tutorial... |
Forum: C Oct 10th, 2008 |
| Replies: 8 Views: 695 May be it was a test on logics and theory of binary arithmetics?..
Sometimes I think that 9 of 10 questions on the C and C++ forums are 100% absurdity...
A la "Urgent help needed! I'm trying to... |
Forum: C Sep 25th, 2008 |
| Replies: 25 Views: 2,931 Let's remember the original post:
I think it's exactly LSB/MSB specification. The author wants to get long integer value where byte a gets 8 least significant bits, b gets the next 8 bits and so... |
Forum: C Sep 23rd, 2008 |
| Replies: 4 Views: 719 Copy/paste all commentaries from the source: it's your desired pseudocode ;)... |
Forum: C Sep 13th, 2008 |
| Replies: 1 Views: 548 Please, read this
http://www.daniweb.com/forums/announcement8-2.html
and this
http://www.daniweb.com/forums/thread78060.html
(especially the last para)... |
Forum: C Sep 11th, 2008 |
| Replies: 10 Views: 1,353 Stricktly speaking it's possible and valid behaviour of floating-point calculations.
Floating point types are not mathematical real numbers. The last ones have "infinit" precision but doubles and... |
Forum: C Sep 4th, 2008 |
| Replies: 11 Views: 1,950 Use double (not float) type for math calculations!
double x, y, z, sum, pi;
...
sum = 1.0;
for (i = 0, y = 3.0; i < n; ++i, y += 2.0)
{
z = 1.0 / y;
if ((i & 1) == 0)
sum -=... |
Forum: C Sep 2nd, 2008 |
| Replies: 1 Views: 911 It depends on OS. No the C language specifications. For Windows see:
http://forums.msdn.microsoft.com/en-US/vclanguage/thread/79b89629-765f-4e9a-9bfb-f99226ef8821/
Unix:... |
Forum: C Aug 9th, 2008 |
| Replies: 14 Views: 1,318 Must be char* foo ( const char *msg ) {, of course ;)... |
Forum: C Jul 26th, 2008 |
| Replies: 3 Views: 481 Judging by the post, sinner has a good chances to go far... |