[英]how to compare user given input(string) to /etc/passwd file in ubuntu in c
I want to compare user given input ie a username to the already stored usernames in /etc/passwd file in ubuntu. 我想将用户给定的输入(即用户名)与ubuntu中的/ etc / passwd文件中已存储的用户名进行比较。 I am trying it in C. any help please
我正在C中尝试
This code prints all the usernames from /etc/passwd. 此代码从/ etc / passwd打印所有用户名。
#include <stdio.h>
int main()
{
char buffer[128];
char* username;
FILE* passwdFile;
passwdFile = fopen("/etc/passwd", "r");
while (fgets(buffer, 128, passwdFile) != NULL)
{
username = strtok(buffer, ":");
printf("username: %s\n", username);
}
fclose(passwdFile);
return 0;
}
Modify to compare username
to your input. 进行修改以将
username
与您的输入进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.