c - 使用c编程创建数据库

标签 c database linux

我想用 C 编程创建数据库。

我想创建员工数据库系统并动态更新它。请指导我如何继续。

我必须为作为闪存的嵌入式系统做这件事。数据库需要存储在那个闪存上,我需要能够动态更新它。文档和建议很有值(value)。

最佳答案

您可以使用结构文件操作 来写入和读取文件。然而,操作可能不像 MYSQL 或任何其他数据库那样快速和高效。

示例代码:

/*  employee database program       */

#include <stdio.h>
#include <string.h>

typedef struct vehicle
{
    char name[100];
    int roll;
    int salary;
    char address[100];
    int join_year;
}record;

int main(void)
{
    int i , choice;
    FILE *fp1,*fp2;
    char oname[100];
    record det;
    int recsize;
    char c;

    fp1 = fopen("record.dat" , "r+");
    if(fp1 == NULL)
    {
        fp1 = fopen("record.dat" , "w+");
        if(fp1 == NULL)
        {
            printf("error in opening file : \n");
            return -1;
        }
    }
    recsize = sizeof(det);

    fseek(fp1 , 0 ,SEEK_END);
    printf("Enter employee Name : ");
    scanf("%[^\n]" , det.name);
    printf("Enter roll number   : ");
    scanf("%d" , &det.roll);
    printf("Enter the salary    : ");
    scanf("%d" , &det.salary);
    scanf("%c" , &c);
    printf("Enter address   : ");
    scanf("%[^\n]" , det.address);
    printf("Enter joining year  : ");
    scanf("%d" , &det.join_year);
    fwrite(&det,recsize,1,fp1);
}

有关在 c 中创建数据库的更多详细信息,您可以从以下指南中获取指导​​ video

关于c - 使用c编程创建数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17107324/

相关文章:

mysql - 计算每个表的行数(其中表名从子查询返回)

mysql - CHAR(0) 允许在 mysql 中插入所有长度的值

c - PIC 微 Controller 的 Modbus 功能代码 1 和 crc 检查

ios - 如何修复此 YCrCb -> RBG 转换公式?

c# - MySQL 访问拒绝 C# 应用程序但不访问工作台

linux - 获取一个文件中不存在于另一个文件中的值

linux - 如何轻松地将 shell 脚本中的所有 echo 语句放入日志文件中

python - 在 CentOS 与 python 2.6 上针对 information_schema 执行 "SELECT"语句时,psycopg2 挂起

c - fread 到达 eof 时的缓冲区条件

c - 添加到 Linux 的系统调用的历史?