在 c 中使用 system() 函数 [英] Using system() function in c
问题描述
我想用system函数来获取windows和linux上的账号数.我不知道去哪里看.请为我指明正确的方向.
I want to use the system function to get the number of accounts on windows and on linux. I have no idea where to look. Please just point me in the right direction.
推荐答案
对于 Linux 系统,您可能希望计算文件 /etc/passwd
中的行数.此文件包含系统中每个用户的条目.
For Linux systems you might like to count the number of lines in the file /etc/passwd
. This file contains an entry for each user to the system.
Linux 下要计算文本文件的行数,可以使用 wc
命令.
To count lines of a text file under Linux the wc
command can be used.
无论如何,如果您在 C 程序中需要此信息,我建议您采用不同的方法:
Anyway, if you need this info in a C program I propose you take a different approach:
您可以使用 fopen()
打开文本文件并使用 fgets()
读取每一行,直到 fgets()
告诉您有没有更多的线路.这样做您将获得用户数量.
You could open a text file using fopen()
and read each line using fgets()
until fgets()
tells you there are no more lines. Doing so you'll be getting the number of users.
这篇关于在 c 中使用 system() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!