c

checking every digit in a number for oddness

Hello. I was writing a function which checks if every digit in a number is odd. I came accross this weird behaviour. Why does the second function return different (incorrect) results, eventhough its basically the same? (implemented in an opposite way) #include <stdio.h> int all_odd_1(int n) { if (n == 0) return 0; if (n < 0) n = -n; ...

sort a struct array by attribute value

Ive got a task in C to sort a struct by using qsort struct user { enum SEX{m, f} sex; char name[32]; char phonenr[32]; }; typedef struct user User; the users will be stored in a array of 25 elements but how do i sort them on something like name ? ...

Why does DestroyWindow close my application?

I'v created a window after creating my main one but calling DestroyWindow on its handle closes the entire application, how can I simply get rid of it? it looks like this: BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; HWND fakehandle; hInst = hInstance; // Store instance handle in our global variable h...

How to add custom line endings in text file (e.g. I want to add a line ending after all periods)

I have a bunch of text files where I want to add a line ending after each period. I'm wondering if there is a way to do this by doing replacing all periods with a \n\n, assuming I have the right encoding (unix). Anyone know how I would do this? Replace .'s with .\n\n and then save as a different file? Thanks! ...

C++ floating point precision

Possible Duplicate: Floating point inaccuracy examples double a = 0.3; std::cout.precision(20); std::cout << a << std::endl; result: 0.2999999999999999889 double a, b; a = 0.3; b = 0; for (char i = 1; i <= 50; i++) { b = b + a; }; std::cout.precision(20); std::cout << b << std::endl; result: 15.000000000000014211 So.. ...

Arithmetic operators and function calling in C

I'm not quite sure why I can't do double a = (double) my_Function(45) / 2048 / 2340 / 90; printf("%.4f",a); // prints out 0.00 But instead I have to use one more variable as: double a = (double) my_Function(45); double b = a / 2048 / 2340 / 90; printf("%.4f",b); // prints out the correct value ...

Bona fide transiant windows with WinAPI?

I want to create a Window like when a context menu pops up or clicking the menubar. I want a Window that will be like this and that I can take over its paint event. Sort of like what is created when you select a sub tool in Photoshop. EDIT:I want to know how to create controls like the one that comes when you select a sub tool in Photo...

Constants by another name

First off, I've seen this question and understand why the following code doesn't work. That is not my question. I have a constant, which is declared like; //Constants.h extern NSString * const MyConstant; //Constants.m NSString * const MyConstant = @"MyConstant"; However, in certain contexts, it's more useful to have this constant ...

Where did the name `atoi` come from?

Ok I've been curious about this for a while. In the C language where did they come up with the name atoi for converting a string to an integer? The only thing I can think of is Array To Integer for an acronym but that doesn't really make sense. ...

Working with a large data object between ruby processes

I have a Ruby hash that reaches approximately 10 megabytes if written to a file using Marshal.dump. After gzip compression it is approximately 500 kilobytes. Iterating through and altering this hash is very fast in ruby (fractions of a millisecond). Even copying it is extremely fast. The problem is that I need to share the data in this...

Why does mmap() fail with ENOMEM on a 1TB sparse file?

I've been working with large sparse files on openSUSE 11.2 x86_64. When I try to mmap() a 1TB sparse file, it fails with ENOMEM. I would have thought that the 64 bit address space would be adequate to map in a terabyte, but it seems not. Experimenting further, a 1GB file works fine, but a 2GB file (and anything bigger) fails. I'm guessin...

access lower and higher 4 bits in type and bind field in elf symbol

What is the best way to access the low-order and high-order 4 bits of the char type and binding field in the elf symbol struct so that I may compare it to STT_FUNC, STT_OBJECT, STB_LOCAL, etc.? ...

DFS function, can you guys tell me what is the wrong with this code?

can you guys tell me what is the wrong with this code? it is not working with 1 2 1 3 1 4 2 5 2 6 2 7 2 8 3 8 3 9 4 10 1 -> 4 -> 10 and stop DFS function void Is_Connected(graphType* g, int v){ //function to define the graph is connected or not int i=0; g_node* w; top = NULL; g -> visited[v] = TRUE; push(v); print...

Eliminating inherited overlong MACRO

I have inherited a very long set of macros from some C algorithm code.They basically call free on a number of structures as the function exits either abnormally or normally. I would like to replace these with something more debuggable and readable. A snippet is shown below #define FREE_ALL_VECS {FREE_VEC_COND(kernel);FREE_VEC_COND(cirra...

delete vs NULL vs free in c++

what is the difference between deleting a pointer, setting it to null, and freeing it. delete ptr; vs. ptr=NULL; vs. free(ptr); ...

how do i avoid this linking error ?

if i have defined a global variable(with initialization) in header file, and included this file in two file and try to compile and link, compiler gives linking error headers.h: #ifndef __HEADERS #define __HEADERS int x = 10; #endif 1.c: #include "headers.h" main () { } 2.c: #include "headers.h" fun () {} ...

extern variable

how to use a variable defined in a header, and using them in multiple source files using extern. I am getting multiple definition error. ...

shared library in C

Hi, I am creating a shared library in C but don't know what is the correct implementation of the source codes. I want to create an API like for example, printHello, int printHello( char * text ); This printHello function will call another function: In source file, libprinthello.c, void printHello( char * text ) { printHi(); ...

null terminating a string

Hello, gcc 4.4.4 c89 just wondering what is the standard way to null terminate a string. i.e. However, when I use the NULL I get the warning message. *dest++ = 0; *dest++ = '\0'; *dest++ = NULL; /* Warning: Assignment takes integer from pointer without a cast */ source code I am using: size_t s_strscpy(char *dest, const char *sr...

recv overwrite a char[]

Hi all, I'm trying to make a little client-server script like many others that I've done in the past. But in this one I have a problem. It is better if I post the code and the output it give me. Code: #include <mysql.h> //not important now #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #includ...