I'm a newcomer to C. (I've good understanding of C# [Visual Studio] and Java [Eclipse]) I wish to create a program that stores information. My first instinct was to utilize a database like SQL Server. However I don't believe that it's suitable for C. Now I've two options:

  • Produce a struct (also typedef) that contains the information types.
  • Try to integrate SQLite via a C header file

Which option do you consider is better? Or have you got an alternative choice? I'm type of leaning toward creating a struct having a typedef, but tend to be pursuaded to alter my thoughts.

ODBC is a C library and permits use of databases inside a mode very similar to JDBC. Microsoft comes with an ODBC driver for SQLServer that's incorporated in Home windows or, for non-Home windows, you are able to leverage something similar to FreeTDS.

Also SQLite supplies a mechanism for additional direct C accessibility database, which allows embedding, etc.

And, based on your storage needs, BDB may be worth looking into.

The question for you is the thing you need. Should you define your personal data structure, you need to manage every aspect of the items you are doing -- if you prefer a variable quantity of records, you will need to manage that space with malloc/free/realloc. If you wish to store data on disk, you will need to write code to read structures. If you wish to index the information, you will need to write code to index it, etc.

As a swap for your, you receive really immediate access, particularly if your requirements are actually simple (e.g., small, fixed quantity of identical records so that you can easily use a range of structs).

Utilizing a database pretty much reverses individuals -- you will get much more versatility to cope with variable kinds of data, more data than you would like in memory, Acidity transactions, building indexes quickly, etc. As a swap for your, you most likely finish track of more code to complete things you might not need, and reduced execution -- particularly if you are storing little enough data that it may all easily fit in memory.

You should use MySQL with C example here http://www.ucl.ac.uk/is/mysql/c/

MySQL is obtainable from C while using Connector/C library.

It seems that MS SQL Server is just suitable for ODBC and does not provide its very own C library. MS continues to be subtly discouraging C development for any very long time, which means this is not surprising.

AFAIK, Oracle, PostGreSQL have their very own C libraries. Many of these may also be utilized via ODBC (including MySQL)

SQLite is mainly an embedded database written like a C library. This only supports a non-standard version of SQL, so it might not be what you would like, but is great for storage of small quantities of data. The C API paperwork are available here.