c

How to debug into internal c code of PHP?

Has anyone here tried it or is it possible? I've been using PHP for quite a few years but never know exactly the underlying c scripts. Is there a way to go into it? ...

combinations algorithm

I want to make simple sorting algorithm. given the input "abcde", I would like the output below. could you tell me the algorithm for that? arr[0] = "a" arr[1] = "ab" arr[2] = "ac" arr[3] = "ad" arr[4] = "ae" arr[5] = "abc" arr[6] = "abd" arr[7] = "abe" ... arr[n] = "abcde" arr[n+1] = "b" arr[n+2] = "bc" arr[n+3] = "bd" arr[n+4] = "be"...

gethostbyname() and valgrind

Hello, I keep getting this error whenever I call gethostbyname() in my C code. ==7983== Invalid read of size 1 ==7983== at 0x412AB2C: ____strtoul_l_internal (strtol_l.c:298) ==7983== by 0x412A46F: strtoul (strtol.c:110) ==7983== by 0x41D427E: inet_aton (inet_addr.c:143) ==7983== by 0x41D8FF3: __nss_hostname_digits_dots (digi...

Printing double variable contents

I tried following code snippet and output is surprising me: #include <stdio.h> #include <math.h> int main() { double num; unsigned char ch; ch = 19; num = 1.0E+20 ; num += ch * 1.0E+18; printf("E18 = %lf \n",num); printf("E18 = %e \n",num); ...

Random directions, with no repeat.. (Bad Description)

Hey there, So I'm knocking together a random pattern generation thing. My code so far: int permutes = 100; int y = 31; int x = 63; while (permutes > 0) { int rndTurn = random(1, 4); if (rndTurn == 1) { y = y - 1; } //go up if (rndTurn == 2) { y = y + 1; } //go down if (rndTurn == 3) { x = x - 1; } //go right ...

Binary Search Tree in C

Hi, I'm a Python guy. Learning C language and I've been trying to implement Binary Search Tree in C. I wrote down the code, and I've been trying from few hours but, not able to get the output as expected. Please help! Please correct me. #include<stdlib.h> #include<stdio.h> typedef int ElementType; typedef struct TreeNode { ElementT...

getc Vs getchar Vs Scanf for reading a character from stdin

Of the below three functions: getc getchar & scanf which is the best one for reading a character from stdin and why? Are there any known disadvantages or limitations for any of these functions which makes one better than the other? ...

How to redirect output away from /dev/null

I have an application that runs the a command as below: <command> <switches> >& /dev/null I can configure <command>, but I have no control over <switches> . All the output generated by this command goes to /dev/null. I want the output to be visible on screen or redirected to a log file. I tried to use freopen() and related functions t...

Can't separate string using sscanf?

Hi, I have a text file of associated numbers i.e; 1 2 2 3 2 1 3 4 3 Each line is a seperate piece of information, as such I am trying to read it in one line at a time and then seperate it into the 3 numbers but sscanf isn't doing what I expect it to. char s[5]; char e[5]; char line[100]; int d; fgets(line, sizeof(line), inFile); ssc...

Details in hex of the certificate in .pem openssl

Hi, I have generated using openssl mycert.pem which contents the certificate. And I converted the base64 text into hex. I wonder if it's possible to extract the informations from the hex string in c (without using the openssl library). For example, the public key, the issuer, the subject, the validity information, etc. Thanks. ...

Search string in file (C)

So my code isn't working... test.c:27: warning: passing argument 1 of ‘search’ from incompatible pointer type which is the fgets line. My code opens a file, reads the file line by line, and I'm trying to create a "search" function that will return a value that indicates whether that string is found on that line of the file. My ultim...

C code autocomplete in Eclipse

Hi, I'm a Java developer and I've downloaded the Eclipse for C (course purposes) and to my amazement the control+space shortcut (for autocomplete) did not work. I've created a new project and a new class using the wizzards and started to type "print" and then tried to find an autocomplete feature. After a bit of googling I arrived at C/C...

How do I convert a G.726 ADPCM signal into a PCM signal?

I usually look to SoX or Window's built in audio libraries for this stuff, but it appears that neither have G.726 codecs. So I have a sequence of bytes that I know are encoded as G.726 although the bit-rate and whether it is mu-law or A-law is not known at this time (experimentation will determine those parameters), and I need to decode...

how to separate debug and release mode code

During debug mode or while I am doing testing, I need to print lots of various information, so i use this method: #ifdef TESTING // code with lots of debugging info #else // clean code only #endif // TESTING` Is this a good method, or is there any other simple and elegant method ? But this way, I am repeating the same code in two pla...

C Struct as an argument

I'm wondering what's the difference between sample1 and sample2. Why sometimes I have to pass the struct as an argument and sometimes I can do it without passing it in the function? and how would it be if samplex function needs several structs to work with? would you pass several structs as an argument? struct x { int a; int b...

Anyone knows a matplotlib equivalent in C or C++

I've been using matplotlib in a Python project. It is great. I have now to plot data in a C++ project. Is anyone aware of a plotting library in C or C++? Note that I cannot accept GPL licensed libraries. ...

Using a database/index sequential file independently of the Unix distribution

What I'm planning to do is a) parse a file for some lines matching a regular expression b) store the match in some sort of database / file so I don't have to do the parsing again and again c) call another program passing the matches as arguments While I can imagine how to do a) and c), I'm a little bit unsure about b). The matches are o...

storing of strings in char arrays in C

#include<stdio.h> int main() { char a[5]="hello"; puts(a); //prints hello } Why does the code compile correctly? We need six places to store "hello", correct? ...

Tree structures and threads

I have a speed critical multithreaded program which involves data in a tree structure. Implemented as follows: typedef struct { // data pertaining to linkages, defining the architecture of the tree int parent_node; int child_node[MAX_CHILD_NODES]; int number_of_children; // data pertaining to info at each node f...

How to generate a random number from within a range - C

This is a follow on from a previously posted question: http://stackoverflow.com/questions/822323/how-to-generate-a-random-number-in-c I wish to be able to generate a random number from within a particular range, such as 1 to 6 to mimic the sides of a dice. How would I go about doing this? I'm used to C# and it seems to be a lot more d...