Read PPM Images in C
Hello!! Does anyone knows how can I read a PPM image into an array using C? Thanks. Best regards. ...
Hello!! Does anyone knows how can I read a PPM image into an array using C? Thanks. Best regards. ...
I've written this piece of code where I've assigned an unsigned integer to two different structs. In fact they're the same but one of them has the __attribute__((packed)). #include #include struct st1{ unsigned char opcode[3]; unsigned int target; }__attribute__((packed)); struct st2{ unsigned char opcode[3]; ...
I'm a web coder: I currently enjoy AS3 and deal with PHP. I own a Nintendo DS and want to give C a go. From a higher level, what basic things/creature comforts are going to go missing? I can't find [for... in] loops, so assume they aren't there, it looks like I'm going to have to declare things religiously, and I assume I have no object...
I'm having a very big struct in an existing program. This struct includes a great number of bitfields. I wish to save a part of it (say, 10 fields out of 150). An example code I would use to save the subclass is: typedef struct {int a;int b;char c} bigstruct; typedef struct {int a;char c;} smallstruct; void substruct(smallstruct *s,bi...
Whilst asynchronous IO (non-blocking descriptors with select/poll/epoll/kqueue etc) is not the most documented thing on the web, there are a handful of good examples. However, all these examples, having determined the handles that are returned by the call, just have a 'do_some_io(fd)' stub. They don't really explain how to best approac...
We have a long standing bug in our production code. This is essentially a socket based daemon. It listens to a bunch of filedescriptors using select. Occasionally (once a day or so), select will return with EBADF. I have written code to search for the bad filedescriptor, that loops over each fd and calls select on it. These calls never...
On some of our linux boxen compiling with gcc -std=c99 makes struct ip_mreq dissappear (included from netinet/in.h) Is there some other interface we are supposed to use ? ...
I'm debugging a network application. I have to simulate some of the data exchanged in order for the application to work. In C++ you can du something like char* myArray = { 0x00, 0x11, 0x22 }; however I can't seem to find a C equivalent for this syntax. Basically I just want to fill an array with hard coded values ...
EDIT: I used, finally, inotify. As stefanB says, inotify is the thing to use. I found a tail clone that uses inotify to implement the -f mode, inotail. Original question text: I'm trying to implement the "tail -f" logic in a C project, for prototyping purposes I developed it in python as follow: # A forever loop, each 5 seconds w...
I've been writing a little program for fun that transfers files over TCP in C on Linux. The program reads a file from a socket and writes it to file (or vice versa). I originally used read/write and the program worked correctly, but then I learned about splice and wanted to give it a try. The code I wrote with splice works perfectly...
I'm using the libpq library in C for accessing my Postgresql database. The application inserts a piece of data fed from a queue. When there is a lot of data and it's inserting very quickly it randomly inserts and empty row into the table. Before I even perform the insert I check to make sure that the length of the text being inserted is ...
I have a pretty large formula that has to be calculated about 300 times per second. Most of my variables are float, but some variables are just parameters that go into that formula. In some cases, float is not needed. I could use int parameters. But I wonder if mixing int and float types in an calculation would cause the system to cast t...
I am developing an application that sits in the system tray and can perform actions on the active window. But when the icon in the system tray is clicked, GetForegroundWindow() returns the taskbar. I need to get the window that was active before the taskbar was. I've tried enumerating the desktop window with EnumWindows and GetWindow, b...
I have a small program to test passing char* pointers in and out of functions. When I compile with cc, I get warning and errors saying I have conflicting types even though all my variables are char* . Please enlighten #include <stdio.h> main() { char* p = NULL; foo1(p); foo2(); } void foo1(char* p1) { } char* foo2(void) ...
I came across this preprocessor definition while reading the source code in Windows Research Kernel (WRK) 1.2: #define assert(exp) ((void) 0) What does this code do? Why is it defined? ...
The example code below works as as a server process. But when I add the line pid_t childpid; below struct sockaddr_in servaddr, clientaddr; it fails at line connectfd = accept(listenfd, (struct sockaddr *) &clientaddr, &clientaddrlen); with the error code 22, EINVAL - invalid argument. I'm new to sockets in C and I couldn't unde...
I'm reading "The C Programming Language (2nd ed.) and near the beginning, it has examples like this: while((c = getchar()) != EOF) if(c == '\n'){ ++n1; I can see how this would work while reading from a file, and I understand this syntax... But this is just reading from the console--how does one signal end of file when ent...
Hello!! I have to make an application that recognizes inside an black and withe image a piece of tetris givem by the user. I read the image to analyze into an array. How can I do something like this using C? Thanks and best regards. ...
Hi, I know how to set file attributes on Windows by using SetFileAttributes function. But I am wondering if there is a native C/C++ function can can do this too? Thanks in advance. ...
Suppose I have this struct (which incidentally contain bit-fields, but you shouldn't care): struct Element { unsigned int a1 : 1; unsigned int a2 : 1; ... unsigned int an : 1; }; and I want to access the i'th member in a convenient way. Let's examine a retrieval solution. I came up with this function: int getval(str...