# Search:

Type: Posts; User: laserlight

Page 1 of 20 1

1. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### Okay, try it with sorted input. Does it work?

Okay, try it with sorted input. Does it work?
2. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### That's because you didn't implement the algorithm...

That's because you didn't implement the algorithm correctly. Look carefully at what should be in which loop.
3. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### Instead of guessing, why don't you go through the...

Instead of guessing, why don't you go through the algorithm with unsorted input and see what you get, and then implement it and try it for an unsorted array to confirm?
4. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### There is a small but critical piece missing...

There is a small but critical piece missing though: after counting with the inner loop, I must be set to J in order to skip those elements that have already been counted.
5. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### Suppose you had input like this: 1 1 1 2 2 3 3 4...

Suppose you had input like this:
1 1 1 2 2 3 3 4 4 4 5
Now, if you want to count the input, it's quite easy: you start with the first number, and set count=1. Then you keep looping over the...
6. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### With the first approach, start by sorting the...

With the first approach, start by sorting the array. Don't worry about the counting yet. You can use the qsort function, or implement your own sort.
7. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### That usually doesn't make sense: the point of...

That usually doesn't make sense: the point of using the static keyword is to give the function name internal linkage. If you declare it in a header, then you're saying that in every separate source...
8. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### Which approach are you trying to implement? I...

Which approach are you trying to implement? I outlined two ways:

1. Sort then make a single pass to count consecutive numbers of the same value.

2. Use a second array to map the numbers to...
9. ## Thread: What is the difference between declaring global or static local variables ?

by laserlight
Replies
2
Views
100

### 1. A static local variable has persistent state...

1. A static local variable has persistent state (due to static storage duration), but local scope. So you avoid name collisions and can manage the state in a more restricted portion of the program...
10. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### Refer to my post #4.

Refer to my post #4.
11. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### That's because you start i at 1 instead of 0.

That's because you start i at 1 instead of 0.
12. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### It looks like you're practically there. Just...

It looks like you're practically there. Just print something indicating that the numbers are repeated.

If you mean repeated more than once in that the numbers have to appear three or more times,...
13. ## Thread: how to compare element of array with other element

by laserlight
Replies
24
Views
514

### Use nested for loops. That's where your j...

Use nested for loops. That's where your j variable can come into play.
14. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### This is a very good opportunity to start though:...

This is a very good opportunity to start though: you're writing a self-contained library such that you don't have to worry about things like mocking a database or a server. Plus it'll look good on...
15. ## Thread: split char array, store and return it

by laserlight
Replies
3
Views
169

### You're welcome. Declaring a function static...

You're welcome.

Declaring a function static affects the linkage of its name. That is, instead of the name referring to that function in all translation units (external linkage, which is the...

by laserlight
Replies
3
Views
129

### Suntani: you posted this twice, and it looks like...

Suntani: you posted this twice, and it looks like you copied and pasted this from somewhere such that you both asked a question and then appear to address the question. Presently, you're giving me...
17. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### Glad to hear that you found and fixed that. ...

Glad to hear that you found and fixed that.

Going back to something I think I've mentioned to you before: have you considered automated unit testing? Right now you have what might be called an...
18. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### Well, I'm clearly not the only one who disagrees...

Well, I'm clearly not the only one who disagrees with you: the experts on the C and C++ standards committees disagree with you that this constitutes a significant attack vector. If not, it would be a...

by laserlight
Replies
12
Views
318

20. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### It's not clear to me how that attack would work...

It's not clear to me how that attack would work in practice without leveraging on another vulnerability, e.g., a typical buffer overflow vulnerability.

So no, I don't think this warrants...
21. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### Such helper functions make your code more...

Such helper functions make your code more readable. It's true that there might be function call overhead, but on the other hand for functions that aren't good candidates for inlining such overhead is...
22. ## Thread: split char array, store and return it

by laserlight
Replies
3
Views
169

### This is wrong: static char t[sizeof(*word)] =...

This is wrong:

static char t[sizeof(*word)] = "";
word is a pointer to char, so sizeof(*word) is equal to 1. Hence, t is an array of char that is only large enough to store an empty string.

If...
23. ## Thread: trying to read numbers from a file - only getting zeros

by laserlight
Replies
4
Views
158

I'd suggest reading in a single pass instead. Do this by reading line by line into a sufficiently long string. Check if the line begins with a '#', and if so, you can skip it. Otherwise, parse it for...
24. ## Thread: I dont know whats going on with my program

by laserlight
Replies
6
Views
439

### davic01: is this supposed to be a C program or a...

davic01: is this supposed to be a C program or a C++ program?
25. ## Thread: Wierd bug in bignum left shift function

by laserlight
Replies
35
Views
481

### For alu_vec, have you considered moving expand...

For alu_vec, have you considered moving expand and shrink into their own functions? For example:

static int _alu_vec_expand( alu_vec_t *vec, int want, size_t perN, int dir, int used )
{
int...
Results 1 to 25 of 500
Page 1 of 20 1