c

How can I debug with piped input in Eclipse CDT?

I'm just starting out using Eclipse CDT. I have a program that processes standard input - so you might execute it on the command line like this: myProg < inputFile.txt I would like to debug the program in Eclipse CDT, with that file as input, but I can't see how to configure this in Eclipse - any ideas? ...

Retrieving stdin after using the redirection operator <

For a programming assignment, we have the following requirements: It needs to be a command-line program written in C. It needs to read text from a text document. However, we are to do this by using the Unix redirection operator < when running the program rather than having the program load the file itself. (So the program reads the tex...

Changing value in memory through an SO in C

I'm writing a .SO that gets called by another program and I want to be able to flip a value in memory through a function in the .SO What I have so far is : int axptrace( int numArguments, char* pMessageBuffer, int* pMessageBufferSize, char* pData[], int* pDataLength[] ) { printf("Beginning dump attempt..\n"); unsigned int* wkp...

Search for string in text file C

The following code reads a text file one character at the time and print it to stdout: #include <stdio.h> int main() { char file_to_open[] = "text_file.txt", ch; FILE *file_ptr; if((file_ptr = fopen(file_to_open, "r")) != NULL) { while((ch = fgetc(file_ptr)) != EOF) { putchar(ch); } ...

Include a source file in a C program

Hello, How can I include foo() function of foo.c in this small program (sorry for my noob question): In my foo.h file: /* foo.h */ #include <stdio.h> #include <stdlib.h> int foo(double largeur); In foo.c: /* foo.c */ #include <stdio.h> #include <stdlib.h> #include "foo.h" int foo(double largeur) { printf("foo"); return 0; } ...

Python, Perl And C/C++ With GUI

Hello, I'm now thinking, is it possible to integrate Python, Perl and C/C++ and also doing a GUI application with this very nice mix of languages? ...

Should this char be unsigned?

I found some confusing code during code review and am a bit puzzled. Doing some research I found this situation. I wrote this sample of code to highlight the problem char d = '©';// this is -87,the copyright symbol , (actually its 169 unsigned) if(ispunct(d)) // will assert. { } so, the programmer who was bug fixing, did the ...

converting from int to float in C changes value

Hi I'm trying to convert from an int to a float in C and for some reason the cast changes the value and I'm not sure why. So: fprintf (stderr, "%d,%d\n", rgbValues->green, (float)rgbValues->green); produces two different numbers. Note that rgbValues->green is an int. Any idea why this is happening? Thanks ...

Writing memory to socket in chunks in C

Hi, I'm attempting to write memory contents to a socket in chunks. I can write files that are smaller than my buffer, but anything else and I'm in deep water. /* allocate memory for file contents */ char fileContents = malloc(sizeof(char)*filesize); /* read a file into memory */ read(fileDescriptor, fileContents , filesize); int chunk...

Why are pointers not located on a stack?

void main(){ int i,k; char* p; int j; printf("address of i is %d \naddress of k is %d \naddress of p is %p\naddress of j is %d", &i,&k,&p,&j); } when I tried the above code, the address of j is 4 units below k. But the address of p is no where near. Since a pointer is an integer variable that could store 4 bytes of dat...

To write a bootloader in C or C++?

I am writing a program, more specifically a bootloader, for an embedded system. I am going to use a C library to interact with some of the hardware components and I have the choice of writing it either in C or C++. Is there any reason I should choose one over the other? I do not need the object oriented features of C++ but it does have a...

Why the SIGSEGV?

Why is this code throwing up a SIGSEGV: int main() { unsigned long toshuffle[9765625]; unsigned long i; for (i=0; i< 1000; i++) toshuffle[i]= i; return 0; } Pointers will be appreciated. (No Pun intended :)) ...

Having problems writing my own malloc, free, and realloc...

I'm having some trouble implementing my own dynamic memory allocator using an Implicit list to track free blocks in c. ****Specifically I'm having problems with implementing realloc and changing the code from find-fit/first-fit to next-fit. Best-fit would be ideal but lets just say next fit for now. I've got everything thing else down,...

What is the format for the headers and message body of a TIBCO-RV packet?

I need to decode a packet sent using TIBCO-RV and pull fields out of the header and skip over the message body. I have not been able to any examples or documentation. Does anybody know of any open source applications that might do this or if there is a Wireshark dissector out there somewhere? ...

How to use a C library from D?

Today I heard about the D programming and that it is compatible to C code. Nevertheless I haven't found any information on whether it is possible to use C libraries like GTK or PortAudio from D? If it is possible, could you explain how to do this? ...

What is useful about this C syntax?

So i dont know everything about C. What is useful about this C syntax? int func (p, p2) void *p; int p2; { return 0; } I was able to write this in visual studios 2010beta //yes the params are flipped void f() { void *v=0; func(5,v); } I dont understand. Whats the point of this syntax? i can write int func (p, ...

Find "edges" in 32 bits word bitpattern

Im trying to find the most efficient algorithm to count "edges" in a bit-pattern. An edge meaning a change from 0 to 1 or 1 to 0. I am sampling each bit every 250 us and shifting it into a 32 bit unsigned variable. This is my algorithm so far void CountEdges(void) { uint_least32_t feedback_samples_copy = feedback_samples; sign...

Explanation of stack overflow when using read on a small file and a questionable workaround

I hope the question explained my problem. I would also be grateful if the workaround that "works" is explained. The traditional way of reading a file (that i know of) int fd; char buffer[MAX]; while(read(fd,buffer,MAX)>0) { buffer[MAX]='\0'; write(sockfd,buffer,MAX); memset(buffer,NULL,MAX); } was causing ...

Objective c library with c interface

Hi everyone, I have run into a problem... I'm trying to use QTKit in an application that we have at work. The only problem with that is the app is written in C++, not Obj-C. I have looked through Apple's documentation for answers, but I haven't found anything useful. Basically what I'm looking to do is write a single controller class i...

Flags, enum (C)

I'm not very used to programming with flags, but I think I just found a situation where they'd be useful: I've got a couple of objects that register themselves as listeners to certain events. What events they register for is dependent on a variable that is sent to them when they are constructed. I think a nice way to do this would be to...