c

C C++ - TCP Socket Class : Receive Problem

Hey, I did my own Socket class, to be able to send and receive HTTP requests. But I still got some problems. The following code (my receive function) is still buggy, and crashing sometimes. I tried debugging it, but it must be somewhere in the pointer arithmetics / memory management. int Socket::Recv(char *&vpszRecvd) { //vpszRecvd =...

C - how can I invoke buffer overflow [hw problem, not hacking]?

Hi! I got a hw assignment asking me to invoke a function without explicitly calling it, using buffer overflow. The code is basically this: #include <stdio.h> #include <stdlib.h> void g() { printf("now inside g()!\n"); } void f() { printf("now inside f()!\n"); // can only modify this section // cant call g(), maybe...

Allocating memory for a char array to concatenate a known piece of text and an integer

I want to concatenate a piece of text, for example "The answer is " with a signed integer, to give the output "The number is 42". I know how long the piece of text is (14 characters) but I don't know how many characters the string representation of the number will be. I assume the worst case scenario, the largest signed 16-bit integer ...

simple comparison of data using double data rate

I can not get to make this comparison in this simple code error .. what kind I'm making and what is the reason? ... #include <stdio.h> int main() { double a = 0.0; double b = 1.0; double c = 0.1; while( a != b ) a=a+c; printf("Suma hasta 1 completada\n"); } tnx for the answers... ...

Why do I get a SIGABRT here?

I have this code segment in which I am opening/closing a file a number of times (in a loop): for(i=1;i<max;i++) { /* other code */ plot_file=fopen("all_fitness.out","w"); for (j=0;j<pop_size;j++) fprintf(plot_file, "%lf %lf\n",oldpop[i].xreal[0],oldpop[i].obj); fclose(plot_file); /*other c...

-fomit-frame-pointer, is it safe to use it?

I've seen in many places that people often use the option -fomit-frame-pointer when compiling C / C++ code and I wonder, is the use of that option safe? What is it used for? Thank you very much, best regards. ...

Fast way to get bitmask for delivery to all devices.

I have a list of devices and a bitmask of channels they are on (channels are numbered 0..3). There can be up to 256 devices. For example: Device1: 1 0 0 1 (on channels 0, 3) Device2: 0 1 1 0 (on channels 1, 2) Device3: 1 1 0 0 (on channels 2, 3) I need to find a bitmask of channels which will result in the message to be received by a...

win32 application aren't so object oriented and why there are so many pointers?

This might be a dumb question to some of you and maybe I asked this question wrong, because I am new to c++. But I notice when working in a lot of win32 applications, you use a lot of resources that are pointers. Why do you have to always acquire a objects pointer ? why not initiate a new instance of the class. and speaking of that, I no...

Can a calculation of floating point differ on different processors? (+passing doubles between C# and C)

I have an application written in C# that invokes some C code as well. The C# code gets some double as an input, performs some calculations on it, pass it to the native layer that perform its own calculations on it, and then passes back to the C# layer. If i run the same exe/dlls on different machines (all of them are x64 by Intel), is...

What's the difference between intializating a struct as pointer or not?

Hi, I have the following for my HashTable structure: typedef char *HashKey; typedef int HashValue; typedef struct sHashElement { HashKey key; HashValue value; } HashElement; typedef struct sHashTable { HashElement *items; float loadFactor; } HashTable; I never really thought about it until now but I just realized th...

Is there a tool to list global variables used and output by a C function?

I want to make a list of global variables/macros consumed by a function and output by the function. For example, for: void myfn(void) { out1 = in + 1; out2 = 2; } ..the tool would list the inputs as 'in' and the outputs as 'out1' and 'out2'. Does anyone know of such a tool? ...

how to compare string in C conditional preprocessor-directives

i have to do something like this in C but it works only if I use a char but I need a string how can I do? #define USER "jack" // jack or queen #if USER == "jack" #define USER_VS "queen" #elif USER == "queen" #define USER_VS "jack" #endif thanks to all! ...

Why check if (*argv == NULL)?

In the data structures class that I am currently taking, we have been tasked with writing a web crawler in C++. To give us a head start, the professor provided us with a program to get the source from a given URL and a simple HTML parser to strip the tags out. The main function for this program accepts arguments and so uses argc/argv. Th...

Recursive mkdir() system call on Unix

After reading the mkdir(2) man page for the Unix system call with that name, it appears that the call doesn't create intermediate directories in a path, only the last directory in the path. Is there any way (or other function) to create all the directories in the path without resorting to manually parsing my directory string and individu...

Using C, why would a char * type be of size 2 in one place, but 4 in another?

From a question on the Practice C test from GeekInterview, why is the size of ptr1 2, while ptr2 and ptr3 are size of 4? main() { char near * near *ptr1; char near * far *ptr2; char near * huge *ptr3; printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3)); } Output: 2 4 4 ...

what happens when tried to free memory allocated by heap manager, which allocates more than asked for?

This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more than n,say N bytes of memory are allocated and free(p) is used to free the memory allocated to p. can heap manager perform such faulty allocation ? what happens now, will n bytes are freed or N bytes are freed? is there any method to find how much m...

error C2228: left of '.DXGI_MODE' must have class/struct/union Direct X

I am trying to setup my swap chain Buffer but I get the following error error C2228: left of '.DXGI_MODE' must have class/struct/union 1> type is 'DXGI_MODE_SCANLINE_ORDER' Note sure what I am doing wrong. here is the code DXGI_SWAP_CHAIN_DESC swapChainDesc; // Set the width and height of the buffers in the swap chain ...

Weird behavior of malloc()

Trying to understand answers to my question http://stackoverflow.com/questions/2336345/what-happens-when-tried-to-free-memory-allocated-by-heap-manager-which-allocates I wrote this function and puzzled by its output int main(int argc,char **argv){ char *p,*q; p=malloc(1); strcpy(p,"01234556789abcdefghijklmnopqrstuvwxyz"); //si...

Open source embedded filesystem (or single file virtual filesystem, or structured storage) library for C

I'm not sure what the "general" name of something like this might be. I'm looking for a library that gives me a file format to store different types of binary data in an expanding single file. open source, non-GPL (LGPL ok) C interface the file format is a single file multiple files within using a POSIX-like file API (or multiple "blob...

Can marshalling or packing be implemented by unions?

In beej's guide to networking there is a section of marshalling or packing data for Serialization where he describes various functions for packing and unpacking data (int,float,double ..etc). It is easier to use union(similar can be defined for float and double) as defined below and transmit integer.pack as packed version of integer.i, ...