c

Help with K&R exercise: Multidimensional array into pointer array.

Exercise (5-9): Rewrite the routines day_of_year with pointers instead of indexing. static char daytab[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; /* day_of_year: set day of year from month and day */ int day_of_year(int year, int month, int day) { ...

Passing an array of strings as parameter to a function in C

I want a simple function that receives a string and returns an array of strings after some parsing. So, this is my function signature: int parse(const char *foo, char **sep_foo, int *sep_foo_qty) { int i; char *token; ... strcpy(sep_foo[i], token); /* sf here */ ... } Then I call it like this: char sep_foo[MAX_QTY...

How to call an external program with parameters?

I would like to call a windows program within my code with parameters determined within the code itself. I'm not looking to call an outside function or method, but an actual .exe or batch/script file within the WinXP environment. C or C++ would be the preferred language but if this is more easily done in any other language let me know ...

Non-blocking mount in Linux

I use Linux's mount(2) function in a single-threaded process. But mounting of devices devices like CD-ROM may take a while (worst I've seen is 40 seconds!), as it will ponder a little, spin up the disk, and only then will mount the filesystem. This may block the process from processing other events for considerable time. I cannot seem t...

Safer Alternatives to the C Standard Library

The C standard library is notoriously poor when it comes to I/O safety. Many functions have buffer overflows (gets, scanf), or can clobber memory if not given proper arguments (scanf), and so on. Every once and awhile, I come across an enterprising hacker who has written his own library that lacks these flaws. What are the best of the...

Variable height items in Win32 ListView

Is it possible to have variable size (owner draw) items in the Win32 ListView, if yes, how? ...

How to Convert 64bit Long Data Type to 16bit Data Type.

I am curious to know How to Convert 64bit Long Data Type to 16bit Data Type. As this feature is required in the Ethernet Application to include Time Stamp. We left with only 2Bytes [16bits] to include Time Stamp. We get 64bit long the Time Stamp from Win API. Any answer will be highly appreciated. Thank you. ...

Any good image processing book?

Hi, I am doing my last CS year project and I need some good documentation about image processing. I'll be doing it in C, probably on an embedded device running UcLinux. ...

C/C++ Header file documentation

Hi! What do you think is best practice when creating public header files in C++? Should header files contain no, brief or massive documentation? I've seen everything from almost no documentation (relying on some external documentation) to large specifications of invariants, valid parameters, return values etc. I'm not sure exactly wha...

best articles about organizing code files in C

Can you recommend me what should I read/learn in order to make a well organized code in C? One of the things I want to learn is the principles of splitting project in .h and .c files, what goes where and why, variable naming, when to use global variables ... I am interested in books and articles that deal with this specific problem. ...

Pointer issues when using sqlite in an objective-c program.

When i try to compile this as part of an objective-c program it gives the warning: warning: passing argument 1 of 'sqlite3_close' from incompatible pointer type sqlite3 *db; sqlite3_open("~/Documents/testdb.sqlite", &db); /*stuff*/ sqlite3_close(&db); An almost identical error is given with nearly any other function call that uses &d...

Code Dependency documentation software

I am looking for a tool to document legacy source code for an embedded C project I work with. I had it in my mind that there was a tool that would create charts of the various C and .h files, but I can't recall what it is called. Does anyone know of such a tool? ...

Error parsing string in C " left operand must be l-value"

I am faced with the need to pull out the information in a string of the format "blah.bleh.bloh" in ANSI C. Normally I would use strok() to accomplish this, but since I am getting this string via strtok, and strtok is not thread-safe, I cannot use this option. I have written a function to manually parse the string. Here is a snippit: ...

Getting started with practical programming

I've been programming small things in C/C++ and even a little Java for a while now. However, I can't seem to break the barrier into programming something that could be considered practical. None of my programs have ever exceeded even 200 lines (and no, I'm not saying that small programs are useless). What is the quickest way to start p...

Stack smashing problem

I am trying to do an example from the Smashing the Stack for Fun and Profit in C, but am kind of stuck at a point, following is the code (I have a 64-bit machine with Ubuntu 64-bit): int main() { int x; x = 0; func(1,2,3); x = 1; printf("x is : %d\n", x); } void func(int a, int b, int c) { char buffer[1]; i...

Should I still learn C if I already know Assembly?

Often one of the main reasons given for learning C is that it brings you closer to programming at a low level which gives you insights into how things really work in higher level languages. I've been programming in various Assembly flavors for awhile and you can't get any lower level than what I have been coding in and I have no illusio...

Does any programmer have to know C? Yes, why? No, why?

Hi, since I was at the first year of my University I always envied my fellows (mainly coming from a tech-oriented professional school) for knowing C. I came from a natural-sciences-oriented lyceum and never had programming experience or courses but some summer work with PHP learned from a teach-yourself-PHP-in-7-hours (and my programming...

Free static code scanner for C/C++/C#

Hi! Does anyone know an open-source and/or free code-scanner for automated code analysis in C#, C or C++? I know for Java there's some brilliant stuff like FindBugs (Eclipse integrated), PMD, or Hammurapi. Is there anything similar for the C-languages? wishi ...

using event handler

is there a way to use mouse as an event handler in c/c++ im a student and got a mini project to do, im making a game on snakes and ladder (the famous board game) and trying to make it with basic borland c++ compiler working with a header file called graphics.h, which is very basic and gives output of 640 X 480 res, so I was wondering if ...

How to find the sizeof( a pointer pointing to an array )

First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\n", sizeof(days)); printf("%u\n", sizeof(ptr)); return 0; } Is there a any way to find out the size of the array that ptr is pointing to? Instead of just giving it's size, which is 4 bytes. Thanks. ...