c

Good lightweight library for HTTP POST/GET for C?

Hi, I'm planning of creating a Last.FM scrobbler plugin for a music player in Windows. Last.FM submissions API relays on HTTP/1.1 GET and POST. I've never done Internet oriented programming and I've still to know about the HTTP protocol but I'd like to start playing around with it sending and getting some data. I've looked at the Winsoc...

Pointers to void pointers in C - can I use void** for rudimentary polymorphism?

I can understand how a void** might look in memory, but I'm wondering if I'm using it quite right. Are there any fundamental flaws in what I describe below? For example, although I can say "it works for me", am I creating bad / unportable code in some way? So I have an Asteroids clone. There are three entities that can fire bullets, the...

Why does C give me a different answer than my calculator?

I've run into an odd problem with this code: legibIndex = 206.385 - 84.6 * (countSylb / countWord) - 1.015 * (countWord / countSent); This is the calculation for the legibility index of a given text file. Since this is a homework assignment, we were told what the Index should be (80, or exactly 80.3) My syllable count, word count, and...

Why Can't we copy a string to Charater Pointer WHEN we can assign a string directly to it?

#include "stdio.h" #include "string.h" int main() { char *p; p="hello world"; printf("p is %s \n",p); return 0; } OUTPUT (on Intel PC): p is hello world #include "stdio.h" #include "string.h" int main() { char *p; strcpy(p,"hello"); printf("p is %s \n",p); return 0; } OUTPUT (on Intel PC): Segmentation fault (core dumped) ...

Memory use when casting? [C]

This is more of a theory question, then any actual code. I understand that if you declare a variable int i; then it sets aside 4 bytes in memory for the integer i. I understand if you use malloc to create your memory as well. I am curious how memory is handled when you do something like int x; int y; double z; z = (float)x/(float)y; ...

How should I get started on writing device drivers?

I would like to learn how to write device drivers because I think it would be fun. I use a Mac OS X Macbook, but I also have an Ubuntu machine (running on a Mac Min). I am pretty familiar with C and currently am reading this book. I have found some links online such as Mac Dev Center. I am doing this because it would be fun. I think ther...

Why can't I use this code to overwrite a string?

Code: #include "stdio.h" #include "string.h" int main() { char *p = "abc"; printf("p is %s \n", p); return 0; } Output: p is abc Code: #include "stdio.h" #include "string.h" int main() { char *p = "abc"; strcpy(p, "def"); printf("p is %s \n",p); return 0; } Output: Segmentation fault (core dumped) Could someon...

gcc compiling invalid C code

Some of my C programs are not working as expected. For example, pass by reference is not possible in C, but when I write a C program which uses that and compile it with gcc it works fine. Is gcc a C++ compiler? How do I make it behave like a C compiler? ...

C++ library works in vb6 but not in c#

Hello, I'm writing a C# application that has to consume a C++ api provided by my customer. The library works fine when it's referenced by a vb6 application, but when I reference it in my c# application and try to call the same methods, i get a different (wrong) behaviour. The methods I'm calling take a couple of string arguments. Provid...

Why can't I use //-style comments in my C code?

I am using gcc (Unbuntu 4.4.1-4unbuntu9) to compile a program that I'm writing, but it seems to vomit whenever it sees a // comment in my code, saying: interface.c :##: error: expected expression before â/â token Does the gcc compile mode I'm using forbid // comments? $ gcc -g -ansi -pedantic interface.c structs.h -c -I. -I/home/me/pr...

Background color for GTK_WINDOW_TOPLEVEL Gtk Widget

In the following code, I want the background colour of the main GTK_WINDOW_TOPLEVEL to be 0xc0deed. But when I run it is appearing black. I even tried gtk_drawing_area_new and adding it to the main window. But still it is appearing black although I could get other colours like red, blue, white etc #include <gtk/gtk.h> int main( int arg...

fwrite with structs containing an array

How do I fwrite a struct containing an array #include <iostream> #include <cstdio> typedef struct { int ref; double* ary; } refAry; void fillit(double *a,int len){ for (int i=0;i<len;i++) a[i]=i; } int main(){ refAry a; a.ref =10; a.ary = new double[10]; fillit(a.ary,10); FILE *of; if(NULL==(of=fopen("test.bin","w"...

How to avoid the interruption of sleep calls due to a signal in Linux

Hello all, I'm using a real time signal in Linux to be notified of the arrival of new data in a serial port. Unfortunately this causes sleep calls to be interrupted when there is signal. Does anybody know of a way to avoid this behavior. Edit: I tried using a regular signal (SIGUSR1) but I keep getting the same behavior. Thanks, Joao ...

Setting TCP receive window in C and working with tcpdump in Linux

I am running a Linux box running 2.6.9-55.ELsmp, x86_64. I am trying to set the TCP receive window by using the setsockopt() function using C. I try the following: rwnd = 1024; setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&rwnd, sizeof(rwnd)); The code segment above is in a client program that receives data from a server. When I k...

GCC Undefined symbols

I recently ditched MacPorts for Homebrew, as a result im now experiencing some issues with make. Namely this error: /Developer/usr/bin/llvm-gcc -rdynamic -o zsh main.o `cat stamp-modobjs` -liconv -ldl -ltermcap -lm -lc Undefined symbols: "_libiconv_open", referenced from: llvm bitcode in utils.o "_libiconv_close", refer...

What is the fastest routine to convert NSArrays to C-style (double) arrays?

Hi all, I have 2 NSArray (Mutable, actually) that I am trying to convert to a C-style double array for a c routine i am passing them to. Here is my Objective-C routine: NSMutableDictionary *childDictionary = [myParentDictionary objectForKey:resort_code]; latitudeArray = [childDictionary objectForKey:@"lat"]; longitudeArray = [childDic...

<template> replacement for C linkedList

Hi All Just finished small linked list in C, and realized that I got a problem :) There is no template arguments for C, so at the start of the file I declaring my data type for list, something like: typedef int LData; So far so good, but I cant use this Linked list for 2(or more) different data types in one program. I can define LDa...

How to save server state of CGI application?

I have a cgi web program (in C) that prints out different error messages to a log file. If the program is run again and runs into he same error, I do not want the same error message to log again. I'm looking at different options and any advice is appreciated. Thanks. -Cookie: unable to set cookie after the html <head> section has been p...

C++ need for Assembly in embedded systems

I hear of a need to call assembly functions/calls when programming embedded systems in C. Is this necessary in C++ or not? ...

How find absolute address of symbol of shared libraries?

I want to write a little function's tracer. I use ptrace. When I see a CALL instruction, I want to show the function name equivalent to the address call. My tracer work with symbols with absolute address (symbol define in the main binary). But I don't know how I can get the absolute address in virtual memory of the function of the shar...