strtok segmentation fault

The problem is that you’re attempting to modify a string literal. Doing so causes your program’s behavior to be undefined. Saying that you’re not allowed to modify a string literal is an oversimplification. Saying that string literals are const is incorrect; they’re not. WARNING : Digression follows. The string literal “this is a test” is of an expression of type char[15] (14 … Read more

Is there a way to compile C++ to C Code?

The C++ FAQ has a list of possibilities: Is it possible to convert C++ to C?. In short, it says that you can’t expect this to give you particularly readable code. Think of the complexities involved; multiple inheritance, virtual-function resolution, templates, operator overloading, etc., etc. There’s no clean succinct way of expressing these concepts in pure C. If … Read more

Example of waitpid() in use?

Syntax of waitpid(): The value of pid can be: < -1: Wait for any child process whose process group ID is equal to the absolute value of pid. -1: Wait for any child process. 0: Wait for any child process whose process group ID is equal to that of the calling process. > 0: Wait for the child whose … Read more

Where does linux store my syslog?

On my Ubuntu machine, I can see the output at /var/log/syslog. On a RHEL/CentOS machine, the output is found in /var/log/messages. This is controlled by the rsyslog service, so if this is disabled for some reason you may need to start it with systemctl start rsyslog. As noted by others, your syslog() output would be logged by the /var/log/syslog file.You can see system, user, … Read more

error: struct has no member named X

Look at the first error message of the compiler. It should complain about the *char in line 6, which should be char *. By the way: always copy and paste error messages, so that we get the original messages.

Does C have classes?

No, C doesn’t have classes. That said, there are ways of simulating object-oriented programming in C – a quick Google search should yield some useful results.

Why and when to use static structures in C programming?

The static keyword in C has several effects, depending on the context it’s applied to. when applied to a variable declared inside a function, the value of that variable will be preserved between function calls. when applied to a variable declared outside a function, or to a function, the visibility of that variable or function is limited … Read more

What do \t and \b do?

Backspace and tab both move the cursor position. Neither is truly a ‘printable’ character. Your code says: print “foo” move the cursor back one space move the cursor forward to the next tabstop output “bar”. To get the output you expect, you need printf(“foo\b \tbar”). Note the extra ‘space’. That says: output “foo” move the cursor … Read more

Should I use printf(“\n”) or putchar(‘\n’) to print a newline in C?

It will make no difference which one you chose if you’re using a modern compiler[1]. Take for example the following C code. When compiled with gcc -O1 (optimizations enabled), we get the following (identical) machine code in both foo and bar: Both foo and bar end up calling putchar(‘\n’). In other words, modern C compilers are smart enough to optimize printf calls very efficiently. Just use whichever … Read more

Categories c Tags
Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)