# Search:

Type: Posts; User: john.c

Page 1 of 20 1

1. ## Thread: Sum of digits in C

by john.c
Replies
8
Views
315

### That's very interesting. After reading it through...

That's very interesting. After reading it through carefully I guess I understand it, but it still seems like magic.
2. ## Thread: Segments of consecutive equal bits

by john.c
Replies
3
Views
181

### A couple of problems. You should only loop up...

A couple of problems.

You should only loop up to i < size - 1 since otherwise 1u<<(i+1) will create 0u on the last iteration.

You should also start counter at 1, since there will always be at...
3. ## Thread: Sum of digits in C

by john.c
Replies
8
Views
315

### Witchcraft! How does that work?

Witchcraft!
How does that work?
4. ## Thread: Cannot figure out the rest of the program

by john.c
Replies
10
Views
348

### Just ignore flp. He's proven again and again...

Just ignore flp.
He's proven again and again that he doesn't know what he's talking about.
He's apparently 51 years old but acts like a baby.
It's pathetic.
5. ## Thread: Cannot figure out the rest of the program

by john.c
Replies
10
Views
348

### For beginners, yes. flp simply doesn't know what...

For beginners, yes.
flp simply doesn't know what he's talking about.
6. ## Thread: Cannot figure out the rest of the program

by john.c
Replies
10
Views
348

### %lf allows spaces before it, but you do need to...

%lf allows spaces before it, but you do need to add some extra spaces to flp's code:

scanf("%lf%c +%lf =%lf", &a, &y, &b, &c)

Or, equivalently, but perhaps more readable:

scanf("%lf%c +...

by john.c
Replies
9
Views
377

### Not exactly, but it demonstrates all the tools...

Not exactly, but it demonstrates all the tools you need.
This is also not quite right but demonstrates a little more:

#include <stdio.h>

int main()
{
printf("N: ");
int N;

by john.c
Replies
9
Views
377

### You use scanf to read the integer N. You use a...

You use scanf to read the integer N.
You use a for loop to go through all the integers from 1 up to N.
You determine the proper divisors of those integers using the modulus operator %.
You must...
9. ## Thread: Cygwin memory allocation / stackdumpfile

by john.c
Replies
7
Views
343

### No you don't. You think they all run as intended....

No you don't. You think they all run as intended.

For example, your rand_double function seems to be incorrect.
You should only seed the rng once in the entire run of the program.
So you should...
10. ## Thread: fgets and size

by john.c
Replies
4
Views
245

### Which is also why fgets leaves the newline in the...

Which is also why fgets leaves the newline in the string. If it's not there (and the stream isn't at eof) then the line was truncated.

by john.c
Replies
9
Views
377

### The question is ridiculous. Is it a joke? The...

The question is ridiculous.
Is it a joke?
The improper divisors of M are just M and 1.
So the answer would always be N.

And it has nothing to do with strings, pointers, strcpy or gets.
12. ## Thread: 2D Array sorting

by john.c
Replies
1
Views
220

### For the horizontal swaps: Select a random row...

For the horizontal swaps:
Select a random row from 0 to N - 1.
Select a random col from 0 to N - 2.
If a[row][col] > a[row][col + 1], swap them.

For the vertical swaps:
Select a random row...
13. ## Thread: How to insert a class object to a binary search tree

by john.c
Replies
5
Views
370

### That's why I said that I assumed tree.insert()...

That's why I said that I assumed tree.insert() made a copy of the data.
14. ## Thread: How to insert a class object to a binary search tree

by john.c
Replies
5
Views
370

### Maybe something like this: int main() { ...

Maybe something like this:

int main()
{
ifstream file("data.txt");
if (!file)
{
cerr << "Cannot open input file.\n";
return 1;
15. ## Thread: Size of a struct

by john.c
Replies
4
Views
250

### There's no reason to pad lastname to 16 since...

There's no reason to pad lastname to 16 since firstName, a char array, can start on any byte.
It's more likely that firstName is padded to 13 so that balance is on an 8-byte boundary.

by john.c
Replies
1
Views
215

### I guess your basic problem is that you set i to 0...

I guess your basic problem is that you set i to 0 every invocation.
However there's a more general problem. You can't accept an actual hex input since you can only input digits 0 to 9 and not A to...
17. ## Thread: How to insert a class object to a binary search tree

by john.c
Replies
5
Views
370

### Instead of this: for (int i = 0;...

for (int i = 0; i < 23;)
{
while (company[i].getPrice() != 0)
{
i++;
}
...

by john.c
Replies
12
Views
424

### For some reason you are not able to describe your...

For some reason you are not able to describe your game clearly.

Now it sounds like you want to keep rolling until you DON'T get a six. So if you roll a non-6 right away, then that's the value of...

by john.c
Replies
12
Views
424

### If you want to keep rolling until you get a 6,...

If you want to keep rolling until you get a 6, summing all the rolls up to but not including the 6, then the average would be 15. That's because the average of the possible values is (1+2+3+4+5) / 5...
20. ## Thread: Question regarding library functions/macros

by john.c
Replies
6
Views
277

### They can be both at the same time. You can...

They can be both at the same time.
You can ensure you call the function by putting parens around the function name in the call.

#include <stdio.h>

void abc(int x) {
printf("func:...

by john.c
Replies
1
Views
197

### The head and tail go in ListType. ...

The head and tail go in ListType.

typedef struct Node {
MovieType *data;
struct Node *prev;
struct Node *next;
} NodeType;

typedef struct{
22. ## Thread: Struct members initialization fails - do not compile

by john.c
Replies
4
Views
323

### You need to use a typecast: #define...

You need to use a typecast:

#define GPIO_EVB_V2_DEF \
(struct GPIO_def) \
{ \
23. ## Thread: Why is my string duplicated in this very simple program?

by john.c
Replies
2
Views
218

### I think laserlight didn't look closely enough at...

I think laserlight didn't look closely enough at the output! :redface:

You haven't given enough room for the strings. The first string is 36 chars long (including the '\0' at the end). Since...
24. ## Thread: Sscanf into struct

by john.c
Replies
2
Views
221

### In main you need to define actual structs, not...

In main you need to define actual structs, not just pointers to structs.
Then pass pointers by using the "address-of" operator, &.

int main() // Don't define argc and argv if you aren't using...
25. ## Thread: Edge Detection Program//Segmentation fault: 11

by john.c
Replies
4
Views
281

### Can you post the full code? In particular,...

Can you post the full code? In particular, iplib2New.c
Attaching an input image (in the correct format) would be useful, too.
Also, you should respond to hamster_nz who responded to your last post....
Results 1 to 25 of 500
Page 1 of 20 1