c

Possible to avoid including whole standard header file because of one method?

I would like to call the "C" function fabs(double); numerous times in my program, but I don't want to include the whole header file. Is this possible? ...

executing php script from C program and store the results in to a variable

I would like to execute php script from the C Program and store the returning content in to a C variable. I tried like following but it doesnt works: C Code: printf("calling php function\n"); execl("/usr/bin/php -q", "/var/www/html/phpinfo.php", NULL); printf("End php function\n"); Php Code: <?php echo "hello"; ?> Envir...

Reading bytes from bmp file

How do I read the bytes from a bmp file using C? ...

Where can I learn more about pointers?

I do not understand pointers. Where can I learn more about them? ...

Please explain this strange output.

#include<stdio.h> #include<conio.h> void print(char *arr); void main() { clrscr(); char temp='r'; print(&temp); getch(); } void print(char *arr) { int arrsz=sizeof(arr); printf("size is %d",sizeof(arr)); printf("char is %c",arr); } Why do I get this output? size is 1 char is e Surely it should say cha...

K&R book "Hello, world" flashes and disappears

All, I'm trying to build an .exe file for the K&R "Hello, world". The code given in the book is: #include <stdio.h> main() { printf("Hello, world!\n"); } When I build & run from Code::Blocks (under Windows XP), I get the prompt window with the "hello world" message. It stays open until I close it manually. However, when ...

How to know which headers are included without looking at the preprocessed code in GCC?

Hi, I've got some big C programs, and I would like to know when I'm compiling this program, which header files are actually included... The simplest solution would be to print the preprocessed code and look but do you know if there's a way to compile and at the same time showing what header files are included ? ...

Inputing characters into arrays in C- follow up

This is a follow up question to a previous question I asked about calculating a straight hand..not exactly the same...This is the method to read in cards- it works- but is there a better way- to do this using console input in C ... void read_cards(int num_in_rank[], int num_in_suit[]) { bool card_exists[NUM_RANKS][NUM_SUITS]; char c...

Help me understand this "Programming pearls" bitsort program

Jon Bentley in Column 1 of his book programming pearls introduces a technique for sorting a sequence of non-zero positive integers using bit vectors. I have taken the program bitsort.c from here and pasted it below: /* Copyright (C) 1999 Lucent Technologies */ /* From 'Programming Pearls' by Jon Bentley */ /* bitsort.c -- bitmap sort...

__libc_lock_lock is segfaulting

I am working on a piece of code which uses regular expressions in c. All of the regex stuff is using the standard regex c library. On line 246 of regexec.c, the line is __libc_lock_lock(dfa->lock); My program is segfaulting here and I cannot figure out why. I was trying to find where __libc_lock_lock was defined and it turns out ...

Returning the terminal cursor to start-of-line with wrapping enabled

I'm writing a filter (in a pipe destined for a terminal output) that sometimes needs to "overwrite" a line that has just occurred. It works by passing stdin to stdout character-by-character until a \n is reached, and then invoking special behaviour. My problem regards how to return to the beginning of the line. The first thing I thoug...

Debug core file with no symbols

I have a C application we have deployed to a customers site. It was compiled and runs on HP-UX. The user has reported a crash and we have obtained a core dump. So far, I've been unable to duplicate the crash in house. As you would suspect, the core file/deployed executable is completely devoid of any sort of symbols. When I load i...

Managing Implicit Type Conversion in C++

I'm working on code that does nearest-neighbor queries. There are two simple ideas that underlie how a user might query for data in a search: closest N points to a given point in space. all points within a given distance. In my code, Points are put into a PointList, and the PointList is a container has the job of keeping track of the...

HP PCL via TCP/IP

Where can I find an example program in C to print to a network attached HP printer. ...

Why do I need setuid(0) within a setuid-root C program that calls an administrative program with system()?

I had to do a dirty Linux hack for somebody so they could start a printer with the cupsenable printername shell command while being a non-root user. I didn't want them to be able to use the entirety of the cupsenable syntax as root, so I just wrote a C wrapper that sanitizes the input in argv[1] and calls system("cupsenable sanitizedprin...

How do I build a Perl hash in C, using SWIG?

I'm trying to create a Perl hash from within a C library. Here's what I've got so far: static void add_string_to_perl_hash ( HV *hv, char * key, char *value ) { SV *obj = sv_2mortal(newSVpv(value, 0)); hv_store(hv, (const char *)key, strlen (key), obj, 0); SvREFCNT_inc(obj); } SV * do_get_test_hash () { static char *foo ="foo"...

GNU readline History feature

I'm using this code for the history features in my shell: http://cc.byexamples.com/20080613/gnu-readline-how-to-keep-a-history-list-of-entered-command-lines/ but when I compile this using gcc, I got this error $ gcc filename.c /tmp/ccay2CgM.o: In function `main': rl.c:(.text+0x9): undefined reference to `rl_abort' rl.c:(.text+0x13): u...

How Program Becomes a Process. How OS makes Program a process

I wanted to know How OS actually makes a program in to process. what are steps Os engages to make program a process. I mean How a Program becomes a Process, what are the parameter OS adds to kernel datastructure before making a program a process Thank you in advance. ...

getopt does not parse optional arguments to parameters

In C, getopt_long does not parse the optional arguments to command line parameters parameters. When I run the program, the optional argument is not recognized like the example run below. $ ./respond --praise John Kudos to John $ ./respond --blame John You suck ! $ ./respond --blame You suck ! Here is the test code. #include <stdio.h...

C: create a pointer to two-dimensional array

Hi, i need a ptr to a static 2-dimensional array. How is this done? static uint8_t l_matrix[10][20]; void test(){ uint8_t **matrix_ptr = l_matrix; //wrong idea } i dont get it, but all kinds of errors like: warning: assignment from incompatible pointer type subscripted value is neither array nor pointer error: invalid use of f...