c

Why can't decrease the size of a struct when substitute old library?

When we are writing a new version of a library we made (in C), we are prohibited from changing, say, the size of a struct to be smaller. Why? Specifically, version 1 has this: struct foo { int a; int b; } version 2 has this: struct foo { char a; char b; } and we seperate struct definition from declaration, so as ...

Handling responses in libcurl

i have a code to send a Form Post with login credentials to a webpage. it looks like this CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the username ...

runtime error (SIGSEGV)

hi, i would be happy to know why i got this error for the problem http://www.codechef.com/problems/AXR1P2 in codechef.com and my code is... #include<stdio.h> #include<stdlib.h> int main() { int *num=0,n=0,i=0,max=0;char *s=""; int sum[9]={1,5,14,20,25,31,32,38,39},dsum[9]={1,7,8,14,19,25,26,32,33},unitdig=0; do { gets(s); *(num+i)=(in...

Getting MATLAB variable (string) from C

Hi! I'm writing a small C application that launchs a Matlab script (.m file). I need to exchange some variables and I don't know how to get an array of chars that exists in Matlab. I'm doing something like this: enter code here result = engGetVariable(ep,"X"); if (!result) { printf ("Error..."); exit -1; } int...

add(a,b) and a.add(b)

how can i transform a method (that performs a+b and returns the result) from add(a,b) to a.add(b)? i read this somewhere and i can't remember what is the technique called... does it depends on the language? is this possible in javascript? ...

C++ wrapper for C library

Hi, Recently I found a C library that I want to use in my C++ project. This code is configured with global variables and writes it's output to memory pointed by static pointers. When I execute my project I would like 2 instances of the C program to run: one with configuration A and one with configuration B. I can't afford to run my prog...

compile C program to MS-DOS environment

i have a small program that uses 32bit object file, and i wish to run it under dos operating system. now, after searching i found DJGPP. is there a way to use DJGPP to compile my program to 16Bit dos executable format? thanks in advance ...

Problem with Precision floating point operation in C

Hi Guys, For one of my course project I started implementing "Naive Bayesian classifier" in C. My project is to implement a document classifier application (especially Spam) using huge training data. Now I have problem implementing the algorithm because of the limitations in the C's datatype. ( Algorithm I am using is given here, htt...

Adding icon to gcc executable and opening in terminal.

I made a program to connect to a device via Bluetooth and send the data to the web using pure C in gcc. I won't be able to implement any GUI portion in the code right now but I need to deploy it to test users for testing. I want to have the executable with an icon so that a user can click on the executable and the program starts in the t...

C file read leaves garbage characters

Hi. I'm trying to read the contents of a file into my program but I keep occasionally getting garbage characters at the end of the buffers. I haven't been using C a lot (rather I've been using C++) but I assume it has something to do with streams. I don't really know what to do though. I'm using MinGW. Here is the code (this gives me ga...

Making a Ubuntu executable.

i have made a program in C using the gcc compiler. Right now it has no GUI components. So, I am basically compiling it with makefile and running it in the terminal. I need to deploy it so that the executable is standalone. So, basically I want the executable to have an icon and when clicked start the program in the terminal. Can anyone t...

How to send Event signal through Processes - C

Hello all! I have an application consisting of two windows, one communicates to the other and sends it a struct constaining two integers (In this case two rolls of a dice). I will be using events for the following circumstances: Process a sends data to process b, process b displays data Process a closes, in turn closing process b Pro...

How do I get rid of these warnings?

This is really several questions, but anyway... I'm working with a big project in XCode, relatively recently ported from MetroWorks (Yes, really) and there's a bunch of warnings that I want to get rid of. Every so often an IMPORTANT warning comes up, but I never look at them because there's too many garbage ones. So, if I can either fig...

How to detect the root recursive call?

Say we're writing a simple recursive function fib(n) that calculates the nth Fibonacci number. Now, we want the function to print that nth number. As the same function is being called repeatedly, there has to be a condition that allows only the root call to print. The question is: how to write this condition without passing any additiona...

Open MPI Sending structure C

Is it possible to send a structure as a datatype in Open MPI? ...

C Pointer Question: &(*struct->struct)

I have a struct defined with the structure as follows (names are different) struct str1 { int field1; struct str2; } And I have a *str1 in a function. I'd like to get a pointer to str2. So I tried &(str1->str2) and was hoping this would return a pointer to str2. Is this incorrect? It doesn't seem to be working. How would I get ...

Strange error(dereferencing pointer to incomplete type)

void get_cwd(char* buf) { char *result; current->fs->pwd; result = get_dentry_path(current->fs->pwd); memcpy(buf, result, strlen(result)+1); kfree(result); } error: dereferencing pointer to incomplete type The error points to current->fs->pwd; includes: #include <asm/stat.h> #include <linux/fs.h> #include <linux...

C: 8x8 -> 16 bit multiply precision guaranteed by integer promotions?

I'm trying to figure out if the C Standard (C90, though I'm working off Derek Jones' annotated C99 book) guarantees that I will not lose precision multiplying two unsigned 8-bit values and storing to a 16-bit result. An example statement is as follows: unsigned char foo; unsigned int foo_u16 = foo * 10; Our Keil 8051 compiler (v7.50 ...

how to create a registry key without using system() in c/c++??

how to create a registry key without using system()/.bat/.reg in c/c++?? ...

read PPM file and store it in an array; coded with C

Hello, I need to read a PPM file and store it in an array written in C. Can anybody help me out doing this? Thanks a lot. ...