Hi guys...
I'm preparing for a quiz, and I have a strong suspicion I may be tasked with implementing such a function. Basically, given an IP address in network notation, how can we get that from a 32 bit integer into a string in it's dotted decimal notation (something like 155.247.182.83)...? Obviously we can't be using any type of inet...
I have a string pointer like below,
char *str = "This is cool stuff";
Now, I've references to this string pointer like below,
char* start = str + 1;
char* end = str + 6;
So, start and end are pointing to different locations of *str. How can I copy the string chars falls between start and end into a new string pointer. Any existing ...
I am trying to debug an issue in my code. I have a process A which runs continuously till I ask it to stop.
Inside A I do the following:
mount partition /dev/sda1
open() // creates an empty file X
write() // write some bytes to it
close() // close the file
processFile() // Perform some operation
remove() // remove file
umount /dev/sda...
Suppose a bit sequence of size M, and another bit sequence of size N, with M >> N. Both M and N can be saved inside integer arrays: If N has a length of 30 then an array with only one integer will be needed, but if N has a length of 300 then an array with 10 integers will be needed to store it.
What I am trying to do is to shift N insi...
Hey guys,
I previously posted how to implement a function that will convert an integer to an IP address string. So how would we go vice-versa, that is, given a string (154.111.23.23) that is an address, how can we get that integer back, using no inet functions.
...
I'm in a scenario when I have to terminate a thread while the thread is running according to user action on GUI. I'm using Qt 4.5.2 on Windows. One way to do that is the following:
class MyThread : public QThread
{
QMutex mutex;
bool stop;
public:
MyThread() : stop(false) {}
void requestStop()
{
...
I'd like to make a TCP client that makes multiple connections while a select() loop that receives data from them is running in a separate thread. I'm not sure this is possible, though, because the select() loop is already running and thus I don't see how it would "notice" a new socket was added even if the thread-safety issues are dealt ...
How do I make sure I've got a double and not something else?
int main() {
int flagOk = 0;
double number;
while(!flagOk) {
printf("Put in a double");
scanf("%lf", &number);
if(number == "%lf"); //this want make sure
flagOk = 1;
}
}
...
EDIT: I can run the same program twice, simultaneously without any problem - how can I duplicate this with OpenMP or with some other method?
This is the basic framework of the problem.
//Defined elsewhere
class SomeClass
{
public:
void Function()
{
// Allocate some memory
float *Data;
Data = new float[1024];
// Dec...
Hi,
I pretty new to Objective-C (and C itself) and need to consume a NSData from a HTTP output. I've never really worked with byte arrays or had to worry about little/big endian issues, and have struggled a bit to write the following method to read a NSNumber with a specified length from that NSData.
- (NSNumber *)readNumberWithLength:...
I have a callback inside a C DLL (static void __stdcall) . I want another program to register it as such (by passing it the func ptr) and then call the calback inside the DLL. I have had no luck so far. However, the same callback works if its inside a regular C++ program. I am now wondering if having callbacks in a DLL is even possible. ...
Hi, I have a message queue from which I am getting messages in a loop. The problem is that I don't know how to exit the loop. msgrcv returns type size_t so it keeps going. What value should I compare the return value so I can exit the loop?
while(msgrcv(msqid, &msgreceived, sizeof(msgreceived), BUFFER_CHANGED, 0) != -1){
printf("%d %d ...
Hello,
I'm trying to simply convert a byte received from fget into binary.
I know the value of the first byte was 49 based on printing the value. I now need to convert this into its binary value.
unsigned char byte = 49;// Read from file
unsigned char mask = 1; // Bit mask
unsigned char bits[8];
// Extract the bits
for (int i = 0; ...
I'm moving some old C code that generates a binary file into our C# system. The problem is, the resulting binary file will still need to be read by another old C program.
The original code outputs several structs to a binary file, and many of those structs contain linked lists, with *next pointers.
How can I write these in C# so that ...
I am trying to extract the mp3 header from a file. This is different then the ID3 tags -- the mp3 header is where information about the MPEG version, bit rate, frequency, etc is held.
You can see an overview of the mp3 header structure here: http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg
My problem is, despite ...
#include<stdio.h>
int main() {
int a = 1;
switch (a) {
int b = 20;
case 1:
{
printf("b is %d\n", b);
break;
}
default:
{
printf("b is %d\n", b);
break;
}
}
return 0;
}
...
#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23, 34, 12, 17, 204, 99, 16};
int main() {
int d;
for (d = -1; d <= (TOTAL_ELEMENTS - 2); d++)
printf("%d\n", array[d + 1]);
return 0;
}
Why is the for loop not run even once?
...
i = 1, 2, 3, 4, 5;
this actually assigns 1 to i.
I wonder if this type of assignment is actually useful somewhere?
Do you know some application of this syntax?
...
I am confused by these two terms. Are they the same?
...
Does anybody know where I can find an example of a Spaghetti stack written in C?
...