Skip to content

Tag: c++

trouble with opening file for read with fopen

I am new to writing c under linux so this will be maybe silly question, but I have problem using fopen. When I encountered the problem I just tried it with this really simple code: test.txt is in same folder as this code and a.out. When I debug a.out I get: I tried changing the path: if( fopen(“/home/h1…

F_SETPIPE_SZ undeclared

I have included following headers: I have also tried to use before #include <unistd.h>, but it also does not help. I try to use fcntl and pass it F_SETPIPE_SZ as second argument, but I keep getting this error message: error: ‘F_SETPIPE_SZ’ undeclared (first use in this function) I actually found out tha…

How to use atomic variables in C?

I need to use an atomic variable in C as this variable is accessed across different threads. Don’t want a race condition. My code is running on CentOS. What are my options? Answer If you are using GCC on your CentOS platform, then you can use the __atomic built-in functions. Of particular interest might…

System commands in c#

Does C# have an equivalent to the system command in C? for example, how would I do this in c#?. I’m using Mono on Linux. Answer No problem I got it. Tested and working on Ubuntu 13.10

Variable reset after scanf

I wrote the below function : I print the currentPlayer on any level to see what’s going on -> here what I get: Why the current player is 0 after scanf? I didn’t touch it. Answer The buffer location has only room for 2 characters and scanf puts an extra NUL character at end. Therefore you have a…