Question about C programming
int a, b; a = 1; a = a + a++; a = 1; b = a + a++; printf("%d %d, a, b); output : 3,2 What's the difference between line 3 and 5? ...
int a, b; a = 1; a = a + a++; a = 1; b = a + a++; printf("%d %d, a, b); output : 3,2 What's the difference between line 3 and 5? ...
I'm trying to call the Matlab engine programatically from a C program on Linux (Matlab r2009a, Ubuntu 9.10). I've got my own code (which works in Windows), but for now I'm just trying to get the Matlab "engdemo.c" program to work on Linux. I have managed to compile & link it (after including about 15 -l<lib> switches on the gcc command ...
Hello, my program generates random numbers with up to 6 digits with int number = arc4random % 1000000; I want that my program do something when a number like 66 or 4444 or 77777 appears (multidigit number with all digits identical). I could manual write: switch (number) { case 11: blabla...; case 22: blabla...; (...)...
I am using C and want to know are XML messages are preferable over text messages as far as communication over a socket connection is concerned? Is there any other good option available rather to go for XML? Which is the best parser(or parsing option) available for parsing XML in C? Is there any standard library which comes with C and ...
I'm looking to write a small program which will intercept network packets (on the local machine) and modify them before they go out on the network. I need to be able to modify the headers as well, not just the data. I've already looked through several possibilities but am unsure which one is best to pursue. There are open source packet ...
I have a library which needs to parse double numbers which always use a point '.' as decimal separator. Unfortunately for this case, strtod() respects the locale which might use a different separator and thus parsing can fail. I can't setlocale() - it isn't thread-safe. So I'm searching for a clean locale-independent strtod implementatio...
Is there a better way to initialise C structures? I can use initialiser lists at the variable declaration point; however this isn't that useful if all arguments are not known at compile time, or if I'm not declaring a local/global instance, eg: Legacy C Code which declares the struct, and also has API's using it typedef struct { i...
Related to this question. What's the process for compiling a C program (assume 1 file)? ...
I need to concatenate two const chars like these: const char *one = "Hello "; const char *two = "World"; How might I go about doing that? I am passed these char*s from a third-party library with a C interface so I can't simply use std::string instead. ...
"As written, getint treats a + or - not followed by a digit as a valid representation of zero. Fix it to push such a character back on the input." Ok, well this is the original version: int getint2(int *pn) { int c, sign; while(isspace(c=getch())) ; if(!isdigit(c) && c!= EOF && c!= '+' && c!= '-') { ung...
The more I hear and read about C++ (e.g. this: http://lwn.net/Articles/249460/), I get the impression, that I'd waste my time learning C++. I some wrote network routing algorithm in C++ for a simulator, and it was a pain (as expected, especially coming from a perl/python/Java background ...). I'm never happy about giving up on some tec...
Just about everyone uses them, but many, including me simply take it for granted that they just work. I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me. Now, C++ is probably a good place to start since you can throw anything in that language. Also, C is close to...
How to write a thread-safe and efficient, lock-free memory allocator in C? By efficient I mean: Fast allocation & deallocation Optimal memory usage (minimal wastage and no external fragmentation) Minimal meta-data overhead ...
The union epoll_data_t looks like: typedef union epoll_data { void *ptr; int fd; __uint32_t u32; __uint64_t u64; } epoll_data_t; This is more of a general C question, but why are the leading double underscores __uint{32,64} types used instead of just uint{32,64} without the underscores? I don't really underst...
Hi, I am working on a C program, and I am coming across a small problem. I don't know how to convert an integer (say 2007) into a char array. Is there a function in the C libraries to do that for me? To clarify, I'd like to take 2007 and store it in some char array[4] ={ '2', '0', '0', '7', '\0' }; I was thinking something like spr...
The function prototype would be: string f (string s); or char* f (char* s); f would transform a string represented by printable ascii char into a raw string. and it would behaves as in the following examples: f("AAA") = "AAA" f("AA\n") = "AA+line_feed" i.e the input string is 4 char long (+ NULL), the output is 3 char long(+NUL...
I'm solving this K&R exercise: Write versions of the library functions strncpy , strncat , and strncmp , which operate on at most the first n characters of their argument strings. For example, strncpy(s,t,n) copies at most n characters of t to s . Full descriptions are in Appendix B. So i was wandering if there's a site that contains s...
Hi, Is there a function in C to check if the input is an int, long int, or float? I know C has an isdigit() function, and I can create an isnumeric function as follows: <blink> int isnumeric( char *str ) { while(*str){ if(!isdigit(*str)) return 0; str++; } return 1; } But I was wondering how t...
Is there any standard library of Matrix in c. Which I can implement across the platform. If not then kindly tell me OS dependent libraries of Matrix. ...
I m using the following flags , but still I m not able to get this warning: "pointer of type 'void *' used in arithmetic" Flags used: -O2 -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wno-sign-compare -Wno-pointer-sign -Wno-attribut...