Search Results

Showing results 1 to 40 of 169
Search took 0.04 seconds.
Search: Posts Made By: Dave Sinkula ; Forum: C and child forums
Forum: C 2 Days Ago
Replies: 7
Views: 184
Posted By Dave Sinkula
Are you sure you've got the correct formula (http://en.wikipedia.org/wiki/Body_mass_index)?

Checking the return value from scanf is a good idea.
#include <stdio.h>

int main(void)
{
float...
Forum: C 15 Days Ago
Replies: 4
Views: 276
Posted By Dave Sinkula
The compiler warns because generally it isn't what someone wants. But multiplying by two is the same as adding self to self.

[edit]Heh. But that won't work with pointers. Probably also for good...
Forum: C 19 Days Ago
Replies: 1
Views: 219
Posted By Dave Sinkula
Expected input and output would be helpful. Providing a small snippet of a simple test, minimal but complete and compilable, would too.

"This code doesn't do what I want (and I'm not going to tell...
Forum: C 21 Days Ago
Replies: 14
Views: 753
Posted By Dave Sinkula
*sigh*

Of course it is. ALL structures of the structures in the first example are populated at compile time. A particular one isn't "selected" in the if tree.
Forum: C 21 Days Ago
Replies: 14
Views: 753
Posted By Dave Sinkula
Your first example may not be working the way you think it is. The #include directive is like a copy-and-paste that happens at compile time. You can't do it at runtime.
Forum: C 26 Days Ago
Replies: 3
Views: 334
Posted By Dave Sinkula
Are any of the suggestions here usable?
http://c-faq.com/varargs/nargs.html
Forum: C 28 Days Ago
Replies: 2
Views: 218
Posted By Dave Sinkula
getline is not standard C.
Forum: C 30 Days Ago
Replies: 6
Views: 224
Posted By Dave Sinkula
Casting is misued a lot of the time. And I would argue that this would be a great example.

If the string itself is nonwritable, the cast silences the warning and passes this nonwritable string to...
Forum: C 30 Days Ago
Replies: 6
Views: 224
Posted By Dave Sinkula
Why not just turn off the warning? :icon_rolleyes:
Forum: C 30 Days Ago
Replies: 6
Views: 224
Posted By Dave Sinkula
Have the code mirror what you're doing:
char *VAR1(const char *VAR2)
Also, make sure you have enough space to write into.

[edit]If he wants the warning...

why would a solution be to silence...
Forum: C Oct 25th, 2009
Replies: 6
Views: 230
Posted By Dave Sinkula
I wrote some snippets on parsing some time ago.
http://www.daniweb.com/code/snippet216535.html
http://www.daniweb.com/code/snippet216569.html
http://www.daniweb.com/code/snippet216682.html...
Forum: C Oct 22nd, 2009
Replies: 2
Solved: skip list
Views: 255
Posted By Dave Sinkula
http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_skip.aspx ?
Forum: C Oct 12th, 2009
Replies: 2
Views: 188
Posted By Dave Sinkula
If your return value for the error condition is not checked, why would the loop break?
void permute (int *A, int n)
{
int i = 0;
for (i=0; i<n; i++) {
/* Pick a random element to move to...
Forum: C Sep 25th, 2009
Replies: 7
Views: 265
Posted By Dave Sinkula
I'm not sure if I fully understand what you're trying to do. Let's see if this "made up" code is close to what it is you want.
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
int...
Forum: C Sep 25th, 2009
Replies: 7
Views: 265
Posted By Dave Sinkula
I'm not a fan of typedefed pointers, I find them obfuscatory.Are you trying to do too much in that first line? Something like this instead?
void foo(WriterPtr *pWriter, int *psize)
{
WriterPtr...
Forum: C Sep 23rd, 2009
Replies: 3
Views: 217
Posted By Dave Sinkula
Do you generally catch the return value of printf?

If you don't need to use the return value, you can quietly discard it if you so choose.
Forum: C Sep 21st, 2009
Replies: 10
Views: 430
Posted By Dave Sinkula
For what inputs?
int main()
{
test_binary(printpair(bitAnd), 0xC0000000, 0x80000000);
return 0;
}

/* my output
bitAnd(-1073741824,-2147483648) = -2147483648
*/
Forum: C Sep 21st, 2009
Replies: 10
Views: 430
Posted By Dave Sinkula
Some quickie test code for my "playing along at home":
#include <stdio.h>

/*
* bitXor - x^y using only ~ and &
* Example: bitXor(4, 5) = 1
* Legal ops: ~ &
* Max ops: 14
* ...
Forum: C Sep 18th, 2009
Replies: 17
Views: 565
Posted By Dave Sinkula
I missed it when this was introduced. There are a few related things that are still missing.I would write it like this:numArray = malloc(size * sizeof *numArray);My preference is to avoid the cast...
Forum: C Sep 17th, 2009
Replies: 17
Views: 565
Posted By Dave Sinkula
For gcc, try to add -Wall -ansi -pedantic.

It's printing, but then the program exits. A short answer is to add a pair of calls to getchar(); before the return 0; in main. More info...
Forum: C Sep 17th, 2009
Replies: 17
Views: 565
Posted By Dave Sinkula
All formatting is in the first string.
printf("%g ", *(array+i), " "); /* main.c:40: warning: too many arguments for format */You can't do that.

This maybe?
for (i=0; i < (int) size; i++)
...
Forum: C Sep 17th, 2009
Replies: 17
Views: 565
Posted By Dave Sinkula
#include <stdio.h>

void printArray(double * array, int size)
{
int i;
for ( i = 0; i < size; i++ )
{
printf("%g \n", *(array+i));
}
}
Forum: C Sep 17th, 2009
Replies: 17
Views: 565
Posted By Dave Sinkula
http://tinyurl.com/n5lq4w

Neither %c nor %d are for double.
Forum: C Sep 14th, 2009
Replies: 8
Views: 281
Posted By Dave Sinkula
You're passing a pointer. You dereference the pointer, modifying what is pointed to. Even if the pointer is a copy of the pointer you want, the contents being pointed to are the same and that is what...
Forum: C Sep 14th, 2009
Replies: 8
Views: 281
Posted By Dave Sinkula
http://c-faq.com/aryptr/aryptrequiv.html
Forum: C Sep 14th, 2009
Replies: 8
Views: 281
Posted By Dave Sinkula
This oughtta help for the compile.void FillArr(student *std,int Size) {
/* ... */
void ShowArr(student *std,int Size) {
/* ... */
FillArr(std,sizeof std/sizeof std[0]);
...
Forum: C Sep 7th, 2009
Replies: 9
Views: 415
Posted By Dave Sinkula
FWIW: http://www.daniweb.com/forums/thread49488.html
Forum: C Aug 28th, 2009
Replies: 4
Views: 343
Posted By Dave Sinkula
Nope. That's the problem code he started with (http://www.daniweb.com/forums/thread214506.html).
Forum: C Aug 28th, 2009
Replies: 4
Views: 343
Posted By Dave Sinkula
A 2D array of chars is a 1D array of strings, so to speak. So if you want a 2D array of modifiable strings, you'll need a 3D array of chars.
char a[][3][6] = {{"item1", "1", "1"}, {"item2", "1",...
Forum: C Aug 28th, 2009
Replies: 8
Views: 356
Posted By Dave Sinkula
Use a forward slash; #include necessary headers.
Forum: C Aug 28th, 2009
Replies: 15
Views: 605
Posted By Dave Sinkula
Since the whole line will be a string, you won't want to use %s for the strings with fscanf; instead you'd probably want %14[^,]. The arguments to fscanf will be pointers, so watch out for that too....
Forum: C Aug 25th, 2009
Replies: 15
Views: 605
Posted By Dave Sinkula
One way:
/** Comma separated, for example. */
void record_write(FILE *file, const clientData *cd)
{
fprintf(file, "%s,", cd->firstName);
fprintf(file, "%s,", cd->surname);
...
Forum: C Aug 24th, 2009
Replies: 3
Views: 368
Posted By Dave Sinkula
If you want to change the value of a pointer in a called function, pass a pointer to a pointer.
#include <stdio.h>
#include <stdlib.h>

#define MAXLINE 100

void foo(char **p,int x, int y)
{
...
Forum: C Aug 20th, 2009
Replies: 15
Views: 495
Posted By Dave Sinkula
Short version: a compiler -- MinGW (http://en.wikipedia.org/wiki/MinGW), gcc (http://en.wikipedia.org/wiki/GNU_Compiler_Collection)
Forum: C Aug 19th, 2009
Replies: 15
Views: 495
Posted By Dave Sinkula
That's too bad, just like the students required to learn on Turbo C. :icon_sad:

[edit]You may want to find a better setup to work with in parallel. Code::Blocks comes with the MinGW port of gcc by...
Forum: C Aug 19th, 2009
Replies: 15
Views: 495
Posted By Dave Sinkula
Danger Will Robinson! That's not a compiler, it's an unfinished toy.

I'd recommend finding a different compiler, yes.
Forum: C Aug 19th, 2009
Replies: 15
Views: 495
Posted By Dave Sinkula
My preference (http://www.daniweb.com/tutorials/tutorial45806.html) is to read a line of input with fgets and then use sscanf to obtain numeric data. It's very much like what you're doing, with fewer...
Forum: C Aug 17th, 2009
Replies: 3
Views: 300
Posted By Dave Sinkula
rand has RAND_MAX, maybe random has something similar.

http://c-faq.com/lib/randrange.html
http://c-faq.com/lib/rand48.html
Forum: C Aug 14th, 2009
Replies: 22
Views: 1,091
Posted By Dave Sinkula
http://www.daniweb.com/code/snippet357.html
Forum: C Aug 12th, 2009
Replies: 22
Views: 1,091
Posted By Dave Sinkula
Read the user input as a string, validate the string according to the specific details for dollar amount entry. Such as, begins with dollar sign, is followed by nothing but digits until a possible...
Showing results 1 to 40 of 169

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC