We see Google, Firefox some AJAX pages shows up list of probable items while user types characters.
Can someone give good algorithm,datastructure for implementing autocomplete ?
...
I have the following C code:
#include <math.h>
int main(int argc, char ** argv)
{
double mydouble = 100.0;
double whatever = round(mydouble);
return (int) whatever;
}
When I compile this, I get the warnings:
round_test.c: In function ‘main’:
round_test.c:6: warning: implicit declaration of function ‘round’
round_test.c:...
Hi,
i'd just like to get some thoughts on the best way to do for loops (in c based languages).
all over the web code samples have for loops which look like this
for(int i = 0; i < 5; i++)
while i used the following format
for(int i = 0; i != 5; ++i)
i do this because i believe it to be more efficent but does this really matter in m...
I am a C beginner, and I am curious why this gives me a Seg Fault everytime:
#include <stdio.h>
#include <stdlib.h>
struct Wrapper {
int value;
};
int main () {
struct Wrapper *test;
test->value = 5;
return 0;
}
I know I don't fully understand pointers yet, but I thought that
struct_ptr->field
is the same as
(*struc...
#include <stdio.h>
#include <signal.h>
void ALARMhandler(int sig)
{
signal(SIGALRM, SIG_IGN); /* ignore this signal */
printf("Hello");
signal(SIGALRM, ALARMhandler); /* reinstall the handler */
}
int main(int argc, char *argv[])
{
alarm(2); /* set alarm clock */
while (1...
When you define a new struct is better to define also an interface to that type
(i.e. "setter" and "getter" functions) or to access members directly via . and -> operators?
EDIT
Plain C programming
...
I am coding a very simple DHCP client in C. I have trouble deciding whether it should use UDP or TCP, what basic commands should it support. I think it should be able to get at least DNS, SMTP, POP3 server information from server.
What else do I need to know? Is there a basic DHCP C implementation available which can help?
...
Hi,
my struct is some like this
typedef struct {
type1 thing;
type2 thing2;
...
typeN thingN;
} my_struct
how to enumerate struct childrens in a loop such as while, or for?
thanks in advance.
...
I would like to automatically generate a Makefile dependency list, but I am using Visual Studio 2005. If I were using GCC, I could pass -M (or one of the many variants) to create this dependency list.
Looking through the command line options to cl.exe, I don't see anything obvious. I can handle tweaking the output with post-processing,...
I am looking at a textbook example of a linked list that implements a stack. I don't understand why using a pointer to a pointer to the stack is necessary for the push operation. See the following example:
bool push( Element **stack, void *data)
{
Element *elem = new Element;
if(!elem) return false;
elem->data = data;
e...
Hi, I'm trying to do a debug system but it seems not to work.
What I wanted to accomplish is something like this:
#ifndef DEBUG
#define printd //
#else
#define printd printf
#endif
Is there a way to do that? I have lots of debug messages and I won't like to do:
if (DEBUG)
printf(...)
code
if (DEBUG)
printf(...)
.....
I'm sketching on some fluid dynamics in Python. After a while, I'm looking for a bit more speed, so I rewrote the actual logic in C and put up some Python bindings (using SWIG).
My problem now is that I don't how to render it in a good way. The logic is run pixel by pixel so pixels are what I want to track and render.
Python gives my a...
I am trying to send over UDP using the following code, but i'm getting strange results.
if((sendto(newSocket, sendBuf, totalLength, 0, (SOCKADDR *)&sendAddr, sizeof(sendAddr)) == bytesSent) < 0)
{
printf("Send error! - %d\n", WSAGetLastError());
}
However say when the totalLength variable is set to 30 the sendto functio...
When I am sending a DNS query to the DNS it returns the header with the format bit set.
Indicating there is a problem with the format, but I am failing to see what it is. Its possible I have misinterpreted the RFC, or misread it but right now I cant seem to work it out.
The DNS structure I am sending looks like this in hex.
Header
00...
How to convert a floating point number into a sequence of bytes so that it can be persisted in a file? Such algorithm must be fast and highly portable. It must allow also the opposite operation, deserialization. It would be nice if only very tiny excess of bits per value (persistent space) is required.
...
This question is intentionally very generic and I'm not much of a C programmer although I dabble here and there. The following code is intentionally vague and probably won't compile, but I hope you get the point...
Handling platform specifics seems dynamically in a compiled language like C seems unnecessary and even scary:
int main(in...
double a = 0.0000005l;
char aa[50];
sprintf(aa,"%lf",a);
printf("%s",aa);
Output:s0.000000
In the above code snippet, the variable aa can contain only 6 decimal precision. I would like to get an output "s0.0000005".
Could you please advice me on how to achieve this?
Thanks
...
Hi, I want to allow users to enter password using command-line interface. but I don't want to display this password on screen (or display "****").
How to do it in C?
Thanks.
Update:
I'm working on Linux only. So I don't actually care about Win or other systems. I tried Lucas' solution and it worked fine. However, I still have another ...
I'm making an Arduino-powered clock, and in the process, I'm trying to format integers into two-digit formatted strings for the time read-out (e.g. 1 into "01").
The following gives me "error: expected primary-expression before '{' token":
char * formatTimeDigits (int num) {
char strOut[3] = "00";
if (num < 10) {
strOut = {'0',...
I won't go into details, but I'm attempting to implement an algorithm similar to the Boyer-Moore-Horspool algorithm, only using hex color values instead of characters (i.e., there is a much greater range).
Following the example on Wikipedia, I originally had this:
size_t jump_table[0xFFFFFF + 1];
memset(jump_table, default_value, sizeo...