c

What is the best way to represent arbitrarily big numbers in c?

I'm working on a project that requires me to work with numbers larger than the largest numerical datatype in c. I was thinking of using structs with bit fields to represent this, but it's already smelling bad. Anyone got any tips? (Not looking for a library, more of a thought process to go behind doing something like this.) ...

struct c dynamically allocate memory

Hello, I am using a struct and I want to initialize a maximum of 10 ports. However, when the program is running it could be a lot less, we don't know until run-time. However, this will be the max. I have never done struct like this before, as I normally dynamically allocate using calloc and delcare like this *ports as the value type. ...

How to put assert into release builds in C/C++

I need to only run ship build and I need to assert on certain condition in release build to see if the problem is fixed. How do I do it? ...

Comparing string data received from a socket in C

I have a question on sockets. I have this code: while(bytes = recv(sClient, cClientMessage, 599, 0)){ This puts the message it recives into cClientMessage and the message is always "Message". How I made an if statement like if(cClientMessage == "Message"){//do func}. Now this code will not do the function I want. I think this is b...

undefined C struct forward declaration

Hello, I have a header file port.h, port.c, and my main.c I get the following error: 'ports' uses undefined struct 'port_t' I thought as I have declared the struct in my .h file and having the actual structure in the .c file was ok. I need to have the forward declaration as I want to hide some data in my port.c file. In my port.h I ...

Edit#3* Need help with counter-controlled repetition and arguments in c language

Okay, so I need to have the output look like a diamond of asterisks, with each row increasing by 2 asterisks until the middle has 9 asterisks...and then the rows decrease. function main has to be: int main (void){ int i; i = 0; while (i < 5){ printline (4-i, i*2+1); i = i + 1; } i = 3; w...

How can I get better profiling?

I need to profile a program to see whether any changes need to be made regarding performance. I suspect there is a need, but measuring first is the way to go. This is not that program, but it illustrates the problem I'm having: #include <stdio.h> int main (int argc, char** argv) { FILE* fp = fopen ("trivial.c", "r"); if (fp) { ...

Expose memory as read-only

In C can a function expose memory that it "manageds" at a lower level as readonly to those calling that function (exposing its address). return * const is not effective but I wondered if I was overlooking a programming tick? Thanks. const uint8_t * get_value(int index) { static uint8_t data[2] = {0, 0}; return (const uint8_t *)&data[i...

How to move the window default scrollbar above the status bar?

Every program does have the scrollbar above the status bar. Right? Well, not mine. When i tried to set up my own scroll bars in my program, i suprisingly made them work! So did i manage to get the status bar work too! Hurray! :-) ...But the status bar is ABOVE the scroll bar, when it should be UNDER the scroll bar. How do i move the scr...

Why would pthread_create() fail with only 2 threads active?

I'm having some trouble in my first foray into threads in C. I'm trying (for now) to write a very simple server program that accepts a socket connection and starts a new thread to process it. It seems to work fine except that it will only create about 300 threads (303, sometimes 304) before pthread_create() fails with the EAGAIN code, wh...

Is 'private' a C keyword?

This question is merely to settle a wager, because I already know the answer and this seemed quicker than reading the standard: Are 'private' or 'public' keywords in ANSI C (or any other C for that matter), or were they only added in C++ (and Java, C#, ...)? ...

Strange OpenCV Distance Transform Results

I'm trying to run a distance transform on a thresholded binary image in order to assist anomaly detection (my hope is that I can detect large changes around the edges of the object), however for some reason, upon running my Distance Transform script, I'm getting a strange banding type of effect. I tested something similar in the Distance...

Problem regarding c-graphics

sir, In my turbo c++ program, I can't run any of the graphics program. When it compile, it shows the error's like: undefined symbol _line, _closegraph,_ getmaxx etc... Is it due to the settings of my c-program? ...

code to change file extension (up for review)

I am using the following piece of C code to change file extension. { #define EVAL_MAX_LEN (300) int nLen; char szOut [EVAL_MAX_LEN] = {0}; char szPath [EVAL_MAX_LEN] = "/db/file/face.bmp"; // Get string length !!! nLen = strlen (szPath); if ((nLen > 0) && (nLen < EVAL_MAX_LEN)) { while (nLen) { // Check for...

converting char** to char* or char

I have a old program in which some library function is used and i dont have that library. So I am writing that program using libraries of c++. In that old code some function is there which is called like this *string = newstrdup("Some string goes here"); the string variable is declared as char **string; What he may be doing in that f...

structure calloc c

Hello, C99 gcc I keep getting this error. I have a struct outside main. And inside main I am trying to allocate on the stack using calloc. I can't seem to find out what is wrong. Thanks for any advice, error: expected expression before ‘)’ token /* global */ struct port_data_t ...

Does malloc() allocate a contiguous block of memory?

I have a piece of code written by a very old school programmer :-) . it goes something like this typedef struct ts_request { ts_request_buffer_header_def header; char package[1]; } ts_request_def; ts_request_buffer_def* request_buffer = malloc(sizeof(ts_request_def) + (2 * 1024 * 1024)); the programm...

How to get my non-loopback network ip address in C?

For a communication between two hosts, I need to send the IP address of my host to the other site. The problem is that if I request my IP address, it might be that I get back my local loopback IP addres (127.x.x.x) , not the network (ethernet) IP address. I use the following code: char myhostname[32]; gethostname(myhostname, 32); hp ...

How can I write a generic C function for calling a Win32 function?

To allow access to the Win32 API from a scripting language (written in C), I would like to write a function such as the following: void Call(LPCSTR DllName, LPCSTR FunctionName, LPSTR ReturnValue, USHORT ArgumentCount, LPSTR Arguments[]) which will call, generically, any Win32 API function. (the LPSTR parameters are essentially be...

for loop in objective-c - primitive array

int matrix[3][3] = { {1,2,3}, {1,2,3}, {1,2,3}, } how can i loop over it? basically the length operation is my concern. for (int i=0; XXXXX; i++) { for (int j=0; XXXX; j++) { int value = matrix[i][j]; } } EDIT: is there a dynamic way of getting the array size? something like sizeof() thank you, chris ...