如何使C查找文件并找到某个字符串?

时间:2019-08-18 22:11:49

标签: c for-loop if-statement do-while modulo

我有一个文件,其中包含以下格式的员工信息:

  

名称:Belal Kassem
  服务:安全性
  生日:1995年
  薪水:500

     

名称:Abdallah Yasser
  服务:市场营销
  生日:1954年
  薪水:500

     

名称:Hend Elkarmouty
  服务:牙医
  生日:1990年
  薪水:800

我希望程序搜索用户指示的员工姓名,然后返回+ newWithName:(NSString *)printerName { ... }true(已找到/未找到)。

但是,现在,我的程序仅询问我要删除的员工人数及其姓名。

false

我还想使用NameFinder变量打印出所有被删除的员工。

1 个答案:

答案 0 :(得分:3)

使用strcmp比较字符串,如下所示:

if(!strcmp(NameFinder, Name[i]))
{                             //This is not the official code.
   printf("%s", NameFinder); //Just to check if it is working or not.
}