# Search:

Type: Posts; User: christop

Page 1 of 20 1

## Search: Search took 0.01 seconds.

by christop
Replies
4
Views
112

### Each node is linked to the previously-allocated...

Each node is linked to the previously-allocated node, making all nodes accessible, so there's no memory leak (except at the very end of the program because the nodes in the linked list are not freed).

by christop
Replies
8
Views
261

### Also here: program for a tough problem....

Also here: program for a tough problem.
3. ## Thread: deep confuse with pointer

by christop
Replies
4
Views
139

### By the way, this line: structure_variable =...

By the way, this line:

structure_variable = malloc (sizeof(structure_variable));

should be:

structure_variable = malloc (sizeof(*structure_variable));
4. ## Thread: excess elements in array initializer

by christop
Replies
6
Views
127

### C'mon, are you just trolling us now? I numbered...

C'mon, are you just trolling us now? I numbered the rows for you.

Your new code is correct, by the way.
5. ## Thread: excess elements in array initializer

by christop
Replies
6
Views
127

### The array has only 2 rows. How many rows are you...

The array has only 2 rows. How many rows are you trying to fit in it? I counted 3:

int array [2][3][4] =

{
{ {1, 2, 3}, { 4, 5, 6} }, //...
6. ## Thread: Lotto 6/49 program

by christop
Replies
43
Views
763

### You need to put something between the numbers if...

You need to put something between the numbers if you want something between the numbers. It's up to you whether that's a space, newline, comma, or something else. Just add the number separator to the...
7. ## Thread: prime number generation, match 10001 prime number

by christop
Replies
10
Views
245

### Unlike Python, indentation means nothing to C....

Unlike Python, indentation means nothing to C. Statements are grouped together (a "compound statement") with braces.
8. ## Thread: I need help with switch case

by christop
Replies
5
Views
213

### First things first: don't call main(). It's not...

First things first: don't call main(). It's not necessary. If you want to return to the function that called your function, use a return statement.

Second, what do you see if you print out the...
9. ## Thread: Lotto 6/49 program

by christop
Replies
43
Views
763

### My take at it: void pick_n(int n, int out[])...

My take at it:

void pick_n(int n, int out[])
{
int pool[POOL_SIZE];
for (int i = 0; i < POOL_SIZE; ++i) {
pool[i] = i + 1;
}
int top = POOL_SIZE;
10. ## Thread: Lotto 6/49 program

by christop
Replies
43
Views
763

### That description sounds like the Fisher-Yates...

That description sounds like the Fisher-Yates shuffling algorithm, except it "shuffles" only 6 numbers and leaves the rest in place.

So yes, it's a good start.
11. ## Thread: global vs static variable

by christop
Replies
10
Views
295

### A compiler that doesn't initialize global...

A compiler that doesn't initialize global variables is non-standard and should be used with care (or, if possible, discarded in favor of one that does follow the relevant standard(s)).
12. ## Thread: How to synchronize file texts with POSIX threads in C

by christop
Replies
14
Views
410

### Post your latest code and we can help.

Post your latest code and we can help.
13. ## Thread: How to synchronize file texts with POSIX threads in C

by christop
Replies
14
Views
410

### Why would the texts not be synchronized? If you...

Why would the texts not be synchronized? If you properly use a mutex in the threads to read lines from the stream, the threads will be synchronized.

This is roughly how I'd do it:

In the...
14. ## Thread: How to synchronize file texts with POSIX threads in C

by christop
Replies
14
Views
410

### One issue I see is that you're opening the file...

One issue I see is that you're opening the file in each thread (and then saving the file handle in a shared variable, fp). It should be opened only once, before the first thread starts.

Another...
15. ## Thread: fgets hanging inside if statement

by christop
Replies
5
Views
208

### Also be careful not to use recursion where it's...

Also be careful not to use recursion where it's not warranted. menu() calls write_func(), which calls add_entry() or remove_entry(), which then calls menu(). Instead of calling menu(), just use a...

by christop
Replies
3
Views
178

### It's not an empty line at the end of the file, as...

It's not an empty line at the end of the file, as a lot of people seem to believe. It's a newline character at the end of each line. A text file with n lines has exactly n newline characters, so a...
17. ## Thread: Attempted to do assignment, can't figure out where it is wrong.

by christop
Replies
5
Views
202

### Which line gets a value for v? Look closely.

Which line gets a value for v? Look closely.
18. ## Thread: Attempted to do assignment, can't figure out where it is wrong.

by christop
Replies
5
Views
202

### What is the value of "v" at this line?

What is the value of "v" at this line?
19. ## Thread: My function is logical?

by christop
Replies
15
Views
378

### Returning a value from a function in all cases...

Returning a value from a function in all cases isn't really adding an error check. The compiler makes it pretty easy to catch where a function fails to return a value too. You don't even need the...
20. ## Thread: probs with coding

by christop
Replies
33
Views
720

### I'm fairly certain that Hodor knows exactly what...

I'm fairly certain that Hodor knows exactly what conio.h is and what ch == 93 is supposed to mean. I took their questions to be rhetorical to help the OP think about them to help them improve their...
21. ## Thread: probs with coding

by christop
Replies
33
Views
720

### Haha, good point. In that case my code will print...

Haha, good point. In that case my code will print "hello". (It's not that clear how to "properly" handle cases like this, as the specifications I've seen in this thread are fairly loose.)
22. ## Thread: probs with coding

by christop
Replies
33
Views
720

### Why not skip the buffer completely? It's not...

Why not skip the buffer completely? It's not necessary:

#include <stdio.h>#include <stdbool.h>

int main(int args, char *argv[]) {

FILE *fp = fopen("text.txt", "r");
23. ## Thread: My function is logical?

by christop
Replies
15
Views
378

### Your code in a complete program: #include...

Your code in a complete program:

#include <stdio.h>
#include <string.h>

typedef struct{
char letters[5]; /* store the letters/numbers. Get it as a string but only use the first */
...

by christop
Replies
30
Views
498

### Hehe, that's what I get for testing stuff with...

Hehe, that's what I get for testing stuff with Cygwin instead of a real Linux system. Yep, it's "exename" in Cygwin but "comm" in Linux.

by christop
Replies
30
Views
498

### There's also /proc/ /exename if you only want...

There's also /proc/<PID>/exename if you only want the executable name:

\$ cat /proc/self/exename
/usr/bin/bash

I think you'll have a problem finding the length of any file under /proc because...
Results 1 to 25 of 500
Page 1 of 20 1