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...
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...
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?
...
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...
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.
...
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.
...
How do I read in a long double in C?
...
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.
...
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?
...
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
...
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...
how to extract the frequency spectrum from a set of discrete data using fft
...
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...
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 ...
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...
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...
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...
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...
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.
...
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...