c

function pointer lookup in shared object and dll

Hello, basically I would like to look up a funtion in a shared object in a platform independent way: I don't want to deal with LoadLibrary/GetProcAddress or dlopen details is there a library that hides the process of looking up a function pointer in shared objects on various operating systems? I would like simply to provide the share...

fgets() function in C

Hi, I know everybody has told me to use fgets and not gets because of buffer overflow. However, I am a bit confused about the third parameter in fgets(). As I get it, fgets is dependent on: char * fgets ( char * str, int num, FILE * stream ); char* str is the ptr to where my input will be stored. num is the max number of characte...

opaque (abstract) data types in C

In File api.h i've #include <stdio.h> #ifndef API #define API struct trytag; typedef struct trytag try; void trial (try *); #endif In file core.h, i've #ifndef CORE #define CORE struct trytag { int a; int b; }; #endif In func.c, i've #include "api.h" #include "core.h" void trial (try *tryvar) { tryvar->a = 1; t...

Multi-threading in C not working on single-core processor?

So I just ran the example from this website and it says the the output should alternate like so: threadFunc says: processing... main() is running... threadFunc says: processing... main() is running... However on my machine it produces this: threadFunc says: processing... threadFunc says: processing... main() is running... main() i...

How to reset pointer of getutent()

Following is the final code I was working on. I can sleep and show again other messages with sleep() but I can't print what I originally wanted which is inside 2nd while loop. As far as I tested, while((ptr=getutent()) != NULL) would be the problem but I don't know how to solve. I would really appreciate if anyone can help me. Thanks No...

C: How do I get a program using getchar to run?

I'm a total C n00b trying to teach myself C off K&R. My question is kind of embarrassingly elementary. OK, here goes: I can't get programs using getchar to give the kind of output I expected. If you happen to have K&R on hand, I'm stuck on exercise 1.13. The question goes, "Write a program to print a histogram of the lengths of words in ...

Unix suid bit problem

Hello guys! I have written a program in c, that do some calculations then creates a folder. That folder's owner is the root user. With an other user I am trying to run this c application. I've got this error: mkdir: lol: Permission denied Ok, I know this error is ok, because I don't have rights for it, but I have read on the internet...

Tool for braceless, whitespace sensitive C syntax

I'm writing some C at the moment and because I like whitespace sensitive syntax, I'd like to write it like this: #include <stdio.h> int main(void) printf("Hello, world!") return 0 Instead of this: #include <stdio.h> int main(void) { printf("Hello, world!"); return 0; } Does anybody know of a tool that will convert the fo...

Creating every possible value of a fixed size array

Hello, I am trying to make some very elementary thing that will cycle through every possible permutation of an array. Really this is being done in assembly, but I'll explain it in C. Basically, say we have an array uint8_t *data=malloc(10); I want to create an algorithm that will print every possible combination of the bytes in the ar...

Linux equivalent of GetCommandLine and CommandLineToArgv?

I wonder if there are some API to get the current process' command line arguments on Linux. I guess I was terribly unclear. The real purpose of the question was about passing unicode file names through command line arguments. ...

Pointer address in a C multidimensional array.

Hi, I'm messing around with multidimensional arrays and pointers. I've been looking at a program that prints out the contents of, and addresses of, a simple array. Here's my array declaration: int zippo[4][2] = { {2,4}, {6,8}, {1,3}, {5,7} }; My current understanding is that zippo is a pointer, an...

How to read the metadata of a MKV movie files in C#?

How to read the metadata of a MKV movie files in C# (or C or C++ or AS3)? for example such creator metadatacreator hasKeyframes hasVideo hasAudio hasMetaData canSeekToEnd duration datasize videosize videocodecid audiosize audiocodecid audiosamplerate audiosamplesize stereo filesize lasttimestamp lastkeyframetimestamp lastkeyframelocati...

Can't create socket on Windows

I have quite an embarrassing problem. The following code simply will not create a socket on Windows; it fails and displays the error message. Could anyone briefly explain why this might be? I'm incredibly confused and frustrated that something so simple is failing. Thank you. int sock; if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) ...

Python equivalent of PyErr_Print()

What is the Python API equivalent of PyErr_Print(), from the C interface? I'm assuming a call in either the sys, or traceback modules, but can't find any functions therein that make calls to PyErr_Print(). Addendum I'm after the Python call to get the same functionality as PyErr_PrintEx(), described as: Print a standard traceback to ...

Problems of a mastermind guessing game in C

I am writing aa mastermind guessing game, but in the “White Check”, I need to remember (know) the positions of all the position “Blacks”. These positions are not required checking again. Then for “each” non-black player “guess” array compare it against “each” non-black computer “answer” array. To find a match. If find any number in the “...

How to write binary data to file in assembler?

I tried a binary write via sys_write syscall (to stdout or file) but I can have only text file. How to have no-text (binary) bytes too? "mov %eax, %ebx;" "mov $4, %eax;" "mov -0x40(%rbp), %ecx;" "mov $14, %edx;" "int $0x80;" Trying with this example I can't have 14 bytes written if they are not text-bytes (...

C++ - global setlocale works, the same locale passed to _vsnprintf_l doesn't

I have following C++ code sample: void SetVaArgs(const char* fmt, const va_list argList) { setlocale( LC_ALL, "C" ); // 1 m_FormatBufferLen = ::_vsnprintf(m_FormatBuffer, Logger::MAX_LOGMESSAGE_SIZE, fmt, argList); setlocale( LC_ALL, "" ); //2 m_FormatBufferLen = ::_vsnprintf(m_FormatBuffer, Logger::MAX_LOGMESSAGE_SIZE, ...

Copying structure and array

Can you please tell me, how to copy a structure & array (pointer to structure and array) between kernel space and user space, in kernel memory using ioctl interface in C language with OMAP? ...

Rules for using the restrict keyword in C?

I'm trying to understand when and when not to use the restrict keyword in C and in what situations it provides a tangible benefit. After reading, "Demystifying The Restrict Keyword", ( which provides some rules of thumb on usage ), I get the impression that when a function is passed pointers, it has to account for the possibility that t...

What encoding used when invoke fopen or open?

When we invoke system call in linux like 'open' or stdio function like 'fopen' we must provide a 'const char * filename'. My question is what is the encoding used here? It's utf-8 or ascii or iso8859-x? Does it depend on the system or environment setting? I know in MS Windows there is a _wopen which accept utf-16. ...