c

Access a function pointer without parenthesis

I have this code: #include <stdio.h> int getAns(void); int num; int main() { int (*current_ans)(void); current_ans = &getAns; // HERE printf("%d", current_ans()); } int getAns() { return num + 3; } However, is it possible to have something in the // HERE spot that allows the next line to be printf("%d", curre...

C file pointer read write issues

Hi, I was trying to make a simple bubblesort program. Read in numbers from a text file and compare them with the next line, sort in ascending order. Now, I've found my program is able to read from the file just fine, it's when I use any write commands (fprintf, or fputs) that everything goes wrong. I've tried using ftell and fseek an...

How do you program safely outside of a managed code environment?

If you are someone who programs in C or C++, without the managed-language benefits of memory management, type checking or buffer overrun protection, using pointer arithmetic, how do you make sure that your programs are safe? Do you use a lot of unit tests, or are you just a cautious coder? Do you have other methods? ...

Variable parameter lists in C++ and C

I'm working on rewriting a C program in C++ to take advantage of OO aspects so it can easily support multiple devices, and one part of the program is an expression evaluator. Expressions can have function calls, and here's the structure for functions. typedef struct { char *name; int argc; void (*func) (); } FUNCTION; Some...

Web based development for the C language

I am a C programmer and new to web development. Which web-C-technology (open source) suits me to learn quickly for web-development? Update: my question is based on both client and server technologies. ...

Monitor the data in a table

How to write a shell script/process which runs like a daemon on Unix and continuously monitors a field in the table and sleeps for 30 sec's. The field value will regularly increase to a maximum value and my process/script which is monitoring will provide a simple select query output to a log file. any approach is preferred. ...

Reading in long double in the C programming language.

How do I read in a long double in C? ...

What is the output of this program?

Hi, when i tried to run compile and execute this statement in a simple c file: main(){ printf("%d");} on HP it's is giving me 64 and on AIX its giving me 804359524. Could anyone tell me what is this behavior. ...

How to print a string in gdb?

I have a variable char* x = "asd\nqwe\n ... " and I want to print it with newlines printed as newlines not backslash n. Is it possible? ...

Solutions for the book "The C Programming Language "; Kernighan Ritchie Ansi C Second Edition?

Are there any solutions somewhere for the exercises in this book? "The C Programming Language Ansi C Second Ed" Kernighan; Ritchie. ISBN10: 0131103628 ISBN13: 9780131103627 ...

How can I run an external program in Perl?

I want to execute a C program using Perl script. What ever inputs are given to the C executable manually, those should be given by my program.. Lets take a simple program, which takes input of two nos. and prints the sum of it. The values should be provided by Perl script. Kindly guide me through some tutorial where I can achieve the s...

Frequency extraction

how to extract the frequency spectrum from a set of discrete data using fft ...

Time into string with HH:MM:SS format (C-programming)

I need to get the current time in a "HH:MM:SS"-format into a character array (string) so I can output the result later simply with a printf("%s", timeString); I'm pretty confused on the timeval and time_t types btw, so any explanation would be awesome:) EDIT: So I tried with strftime etc, and it kinda worked. Here is my code: time_t c...

Finding out if a message over tcp was delivered

When i send()/write() a message over a tcp stream, how can i find out if those bytes were successfully delivered? The receiver acknowledges receiving the bytes via tcp, so the senders tcp stack should know. But when I send() some bytes, send() immediately returns, even if the packet could not (yet) be delivered, i tested that on linux ...

Getting RGB values for each pixel from a 24bpp Bitmap in C

Hello, i want to read the RGB values for each pixel from a .bmp file , so i can convert the bmp into a format suitable for gba . so i need to get just the RGB for each pixel and then write this information to a file. i am trying to use the windows.h structures : typedef struct { char signature[2]; unsigned int fileSize; u...

objC/C- combined: letting a C function wait till an objC-Delegate is finished

I'm having a problem here: I have a C function: int my_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; alertViewDelegate = [FirewallRest alloc]; [alertViewDelegate retain]; //ALog(@"1"); int error; //ALog(@"2"); char hostname[NI_MAXHOST...

Algorithm: efficient way to remove duplicate integers from an array

I got this problem from an interview with Microsoft. Given an array of random integers, write an algorithm in C that removes duplicated numbers and return the unique numbers in the original array. E.g Input: {4, 8, 4, 1, 1, 2, 9} Output: {4, 8, 1, 2, 9, ?, ?} One caveat is that the expected algorithm should not required the...

Programatically setting a PNG to a Picture Control in Win32 APIs

I use Visual Studio 2008, I have the PNG file loaded in the Resource View, assigned it IDB_BANG_PNG. The Picture Control is called IDC_STATIC15. I am having trouble trying to get the PNG loaded into the picture control. LRESULT CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { // Way of loading a bmp with a...

Calculate the size to a Base 64 encoded message

I have a binary string that I am encoding in Base 64. Now, I need to know before hand the size of the final Base 64 encoded string will be. Is there any way to calculate that? Something like: BinaryStringSize is 64Kb EncodedBinaryStringSize will be 127Kb after encoding. Oh, the code is in C. Thanks. ...

C Threaded Programming - Incrementing a shared variable

Hey guys...so I'm trying to brush up on my C threads and a question I've found is this: Given a global variable int x = 0; implement the function void useless(int n) which creates n threads which in a loop increase x by 1, each thread terminates when x reaches 100. I just don't have a handle on threads and need a solid example to base...