如何在C中搜索和更新文件中的数据? [英] How to search and update data in files in C?

查看:112
本文介绍了如何在C中搜索和更新文件中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个关于C语言超市中使用的客户详细信息的项目。

首先,我将输入所有客户详细信息,例如客户ID,姓名,电话号码,信用积分,...... ..到文件。

然后如何使用文件中的客户ID或电话号码搜索特定客户。

如何更新他的信用积分。每购买100美元,客户将获得1个积分。



我尝试过:



读取文件末尾的文件。

I am doing a project on customer details used in a supermarket in C language.
First I will enter all the customer details such as customer Id,name,phone number, credit points,....into a file.
Then how to search for a particular customer using customer id or phone number in the file.
How to update his credit points. 1 credit point will be given to a customer for every purchase of $100.

What I have tried:

reading a file upto end of the file.

推荐答案

100。



我尝试了什么:



读取文件末尾的文件。
100.

What I have tried:

reading a file upto end of the file.


一般来说你需要:

  • 将文件读入内存
  • 修改内存内容
  • 回写修改后的内存内容到原始文件(覆盖它)
Generally speaking you need to:
  • read the file into memory
  • modify the memory content
  • write back the modified memory content to the original file (overwriting it)


或多或少,你在一个文件中创建一个数据库。

如果你不关心细节,每个操作涉及完整的文件重写te。

More or less, you are creating a database in a file.
If you don't take care about details, every operation involve a complete file rewrite.
Quote:

然后如何使用文件中的客户ID或电话号码搜索特定客户。

Then how to search for a particular customer using customer id or phone number in the file.



重新读取文件,找到每条记录所需的字段并寻找匹配。



1避免解决方案重写问题是使用固定长度字段,就像dBase一样。 .dbf - 维基百科,免费的百科全书 [ ^ ]

或求助于SQL


by rereading the file, locating the needed field of each record and looking for a match.

1 solution to avoid the rewriting problem is to use fixed length fields just like dBase used to do. .dbf - Wikipedia, the free encyclopedia[^]
or resort to SQL


这篇关于如何在C中搜索和更新文件中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆