c

Counting characters in C

Hi all I'm trying to write a program that counts all the characters in a string. I originally had it, but then realized I can't count spaces. I can't see why this does not work. for(m=0; z[m] != 0; m++) { if(z[m] != ' ') { charcount ++; } } Any assistance appreciated. Edit* Does it make a difference if the input(str...

C DBus : Fails when calling method returning string

Cant please someone tell me why the code below crashes when executing, (compilation goes OK) it in rotated X environment 90 to left. DBusGConnection *connection; DBusGProxy *proxy; GError *error = NULL; gchar *name = NULL; g_type_init (); //Get the connection and ensure the name is not used yet connection =...

How to use the "pcap_lookupdev()" in libpcap ?

The code cant find any device, I want to know what does pcap_lookupdev() do ? thanks #include <pcap.h> int main(int argc, char *argv[]) { pcap_t *handle; char *dev;// = "eth0"; char errbuf[PCAP_ERRBUF_SIZE]; dev = pcap_lookupdev(errbuf); if (dev == NULL) { fprintf(stderr, "Couldn't find default device: %s\n"...

bayesian network library for iphone?

i m looking for a bayesian network library that work on the iphone. any tip ? ...

OpenGL ARB function in Mac

I want to use glCurrentPaletteMatrixARB in Mac application. OpenGL library is imported GLEW library and GLUT and, glewInit() function calling was successful. glWeightPointerARB function is able to call, but my application crashed in glCurrentPaletteMatrixARB. Reason is function pointer value is null pointer error. Extension string is no...

State-of-the-art for embedding scriptable, interactive SVG in Gtk+ applications?

I'm interested in writing a Gtk application that uses an embedded SVG canvas for graphics, and I'm wondering what the current state-of-the-art is for using SVG in Gtk. I know that it's possible to embed Webkit inside of Gtk, and so that seems like one approach, but I would like to add interactivity to DOM elements in the embedded SVG can...

Error passing C array as char* function parameter

I'm trying to make a simple code in c language (Stupid question, but I'm learning), I dont understand that this code gives me an error ... I must be doing wrong, I can not know that I have to change...sorry for my English ... thanks in advance to all #include <stdio.h> #include <ctype.h> char* to_up(char* str_); int main() { cha...

trying to understand C, does this set a function equal to a char[] to execute the char[]?

static char yes[80]; int main(int argc, char *argv[]) { void (*point)(); // ... sets yes[] = to input point = (void*) yes; (*point)(); } so does this create a function and execute commands that are in yes[]? how does it know to read the commands in yes? do i type in c, or does it have to be assembly? ...

Strange fgets() problem

I'm trying to run this code on Windows 7 (64-bit, if it matters) after compiling it with GCC. If I declare bufsize as an int, the program freezes and Windows informs me that it's stopped working. If I use #define bufsize 123 it works fine, and it works fine if I replace bufsize with a number myself. What am I missing here? int mai...

copy smaller array into larger array

I have two arrays of chars, allocated as follows: unsigned char *arr1 = (unsigned char *)malloc((1024*1024) * sizeof(char)); unsigned char *arr2 = (unsigned char *)malloc((768*768) * sizeof(char)); I would like to copy arr2 into arr1, but preserve the row/column structure. This means that only the first 768 bytes of each of the fir...

create a random number less than a max given value

What i would love to do is to create a function that takes a parameter that is the limit of which number the random generation should create. I have experienced that some generators that just repeat the number generated over and over again. How can I make a generator that doesn't return the same number consecutively. Can someone please...

Reading the whole text file into a char array in C

Hi, I want to read the contents of a text file into a char array in C. Newlines must be kept. How do I accomplish this? I've found some C++ solutions on the web, but no C only solution. Thanks! Yvan Edit: I have the following code now: void *loadfile(char *file, int *size) { FILE *fp; long lSize; char *buffer; fp =...

c assignment, averaging integers

I worked on this yesterday about 5 hours and got the code to work using help from this site, but I think the way I did it was a cheater way, I used a scanf command. Anyways I want to fix this the correct way. Thanks guys! Oh the code compiles but the average that gets spit out is wrong. I would like to conceptually understand what I ...

Segfault: don't know where to start.

Hi, I'm trying to compile this program under Windows (it's a program which turns bootable code in floppies. I got the source from here: http://www.acm.uiuc.edu/sigops/roll_your_own/1.bootstrap.html). First I got the problem that it didn't read the INI file. That is solved now. Now I get a segfault on the following rule: while(data < e...

How actually does this if statement work

It has been a popular question that how to print hello world without using semicolon.I know many codes but this one sounds weird because I am unable to get the logic behind it.Please help me know how it prints. if(printf("hello world")){} ...

USART transmit problems on a PIC

I'm trying to send data to an SD card from a PIC18f4580, but the PIC is not sending what it should be. related global variables: unsigned char TXBuffer[128]; //tx buffer unsigned char TXCurrentPos = 0x00; //tracks the next byte to be sent unsigned char TXEndPos = 0x00; //tracks where new data should be put into the array I am adding ...

cblas_dgemm - works ONLY if (beta) is power-of-two

Hi, I am totally stumped. I have a fairly large recursive program written in c that calls cblas_dgemm(). The result is verified independently by a program that works correctly. C = alpha*A*B + beta*C On repeated tests using random matrices and all possible combination of parameters the program gives correct answer ONLY if abs(beta) ...

which side of the expression gets evaluated first?

Will the right side of the expression get evaluated first or the left ? void main () { int i = 0 , a[3] ; a[i] = i++; printf ("%d",a[i]) ; } ...

I want a function that reads in a file and returns the sum of ascii values

I want a function that reads in a file and returns the sum of ascii values. I have looked at this page: http://stackoverflow.com/questions/1292630/how-to-open-a-file-and-find-the-longest-length-of-a-line-and-then-print-it-out/1292676#1292676 and the answer to my question was probably starring me in the face, but I cant follow the cod...

OTP/XOR Cracking two ciphertexts that have the same key

How can I crack two ciphertexts that have used the same key twice? For example, plaintext1 uses the key "abcdefg", and plaintext2 uses the key "abcdefg". I know that ciphertext2 ^ ciphertext1 is equal to plaintext1 ^ plaintext2. And the method to crack plaintext1 ^ plaintext2 is the same method to crack a "book cipher" (also sometimes c...