c

Data loss when downloading data from LDAP server

Hi there. This question comes from a previous one I asked about handling NSData objects: http://stackoverflow.com/questions/2453785/converting-nsdata-to-an-nsstring-representation-is-failing. I have reached the point where I am taking an NSImage, turning it into NSData and uploading those data bytes to the LDAP server. I am doing this l...

What's the difference of pData1 and pData2, which are build as follows

What's the difference of pData1 and pData2, which are build as follows: pData1 = (int*) calloc (i,sizeof(int)); int * pData2 = (int*) calloc (i,sizeof(int)); ...

ignore extra spaces when using fgets

I'm using fgets with stdin to read in some data, with the max length I read in being 25. With one of the tests I'm running on this code, there are a few hundred spaces after the data that I want - which causes the program to fail. Can someone advise me as to how to ignore all of these extra spaces when using fgets and go to the next lin...

i just want to use the iptables command in my c program.

i m designing a simple c code to call the iptables command according to the need. i just want to drop the packets from a particular ipaddress using my c code. thats why i have to use the iptables command according to input given. is it possible to call the command using c code? if it is then how??? thanks in advance.. ...

If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2)

How to get he upper limit of a number in C? If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2). ...

How to find all the file handles by a process programmatically?

I have a process "x" which uses "system" C function to start ntpd daemon. I observed that ntpd are passed the open file descriptors of "x". ntpd holds on to the file descriptors even after original file is deleted. for ex: Some log files used by "x" are rotated out after sometime, but "ntpd" has file handle opened for these deleted file...

CGRect in C code

A simple google search for: CGRect + C or CGRect in C brings back only Apple, iPhone, and Objective-C websites. However, I remember hearing that Core Graphics was part of C at my university. Did I hear incorrectly, or is CGRect something that I can use in C, or even C++ as it's Object oriented? ...

Alternate format specifiers for long long in C

Is there any other (alternative) format specifiers for long long in C other than %lld which can be safely used in scanf under gcc? I am aware that %lld does it's job fine; I am just inquisitive :-) ...

redrawing on ncurses

I'm trying to redraw the content of a simple loop. So far it prints out to the stdscr 100 lines, and then by using scrl to scroll n lines I get n blank rows. What I want is to keep with the sequence. However, I'm not sure how to redraw the stdscr with the n extra lines. Any ideas will be appreciate it! #include <ncurses.h> int main(vo...

C : converting binary to decimal

Hi All, Is there any dedicated function for converting the binary values to decimal values. such as (1111 to 15 ) , ( 0011 to 3 ) . Thanks in Advance ...

algorithm to find overlaps

Hey, Basically I've got some structs of type Ship which are going to go on a board which can have a variable width and height. The information about the ships is read in from a file, and I just need to know the best way to make sure that none of the ships overlap. Here is the structure of Ship: int x // x position of first part of shi...

C : Memory layout of C program execution

Hi All , I wanted know how the kernel is providing memory for simple C program . For example : #include<stdio.h> #include<malloc.h> int my_global = 10 ; main() { char *str ; static int val ; str = ( char *) malloc ( 100 ) ; scanf ( "%s" , str ) ; printf( " val:%s\n",str ) ; free(str) ; return 1 ; } See, In this program I...

Easiest way of unit testing C code with Python

I've got a pile of C code that I'd like to unit test using Python's unittest library (in Windows), but I'm trying to work out the best way of interfacing the C code so that Python can execute it (and get the results back). Does anybody have any experience in the easiest way to do it? Some ideas include: Wrapping the code as a Python C...

Run C or C++ file as a script

So this is probably a long shot, but is there any way to run a C or C++ file as a script? I tried: #!/usr/bin/gcc main.c -o main; ./main int main(){ return 0; } But it says: ./main.c:1:2: error: invalid preprocessing directive #! ...

help using pcap library to sniff packets

i am using pcap sample codes to create my own sniffer. i downloaded their sample sniffer and its working on windows but not on linux. i am using gcc compiler on both machines, and i have only pcap.h included. the error is : dereferencing pointer to incomplete type. the netmask is causing the error. the netmask is the mask of the first ad...

symbolic constants

#include<conio.h> #include<stdio.h> #define abc 7 int main() { int abc=1; printf("%d",abc); getch(); return 0; } why this program is giving compile time error ...

Is getchar() equivalent to scanf("%c",&a)?

Is getchar() equivalent to scanf("%c",&a);? Is putchar(c) equivalent to printf("%c",a); where a is a char variable? ...

How to use sprintf instead of hardcoded values

I am developing a firewall for Linux as my project. I am able to capture packets and to block them. I am using IPTABLES. How can I use variables with sprintf instead of hardcoded values? sprintf(comm, "iptables -A INPUT -s $str -j DROP") // inplace of: sprintf(comm, "iptables -A INPUT -s 192.168.0.43 -j DROP") ...

what is difference between fork and thread

Hi All, Can you any one explain me about what is difference between fork and thread ..? Thanks ...

webdav implementation in c

Hello Everyone, I would like to know do we have any webdav protocol implementation in c or c++. Thank You in advance.. ...