How to add, delete edit username from /etc/passwd [duplicate] - c

This question already has answers here:
How to create a linux user using C/C++?
(3 answers)
Closed 6 years ago.
I want to add or delete or edit usernames of /etc/passwd in a C program. Are there any standard Linux functions that do a such functions?

There is adduser and deluser. Use man deluser for details.
EDIT: i missed the C part in the question.
man is also your friend in this case. With man 3 deluser you can ask if there is anything in stdlib called like that. Read https://unix.stackexchange.com/questions/3586/what-do-the-numbers-in-a-man-page-mean for more informations on that.
This is not the case. You might want to call the unix tool from within C: How do you write a C program to execute another program?

Related

How to search for command line arguments in C? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have compiled and run a C code (a lot of files) but I need to understand the physical meaning of the command line arguments.I run code like this
./testmt signal1 3 5 1 1
where
signal1 is the input file
How to search multiple .c files in order to find command line arguments(hopefully with commented lines)?
It is operating system specific. I guess you are on Linux or some other Posix system. Read first Advanced Linux Programming. Read also about globbing. Be aware that your Unix shell is expanding the arguments (and after expansion calling the execve(2) system call....). If you shell is bash (and actually that behavior is mandated by POSIX) read about Shell Operation then about Shell expansions. Read also the Program Arguments chapter of libc documentation. See also my answer on "good habits for designing command line arguments?".
The main function (of signature int main(int argc, char**argv);, and such a [possible] signature is defined by the C standards) - of the program started by execve - gets the positive argument count and a NULL terminated array of strings. So in your case (./testmt signal1 3 5 1 1) you get argc=6 and argv[0] is "./testmt", argv[1] is "signal", argv[2] is "3", etc... argv[5] is the last "1" and argv[6] is NULL.
So dive into your code, and look for main.
PS. AFAIK, on Windows the behavior is probably different. The program (not the shell) is expanding the arguments (actually, probably done in startup files, before they call main). But I know nothing about Windows. See also Operating Systems: Three easy pieces.

How can I change the shell directory in the C language program? [duplicate]

This question already has answers here:
Is there any way to change directory using C language?
(6 answers)
Closed 6 years ago.
When I use chdir() to change the current directory, the program will not change when the program is shut down. So How can I apply chdir() to Shell after using chdir() and programs have been terminated?
You cannot do that (changing your parent shell directory from inside a C program). The current directory is an attribute of every process, and your shell runs in a different process than your program (so the shell process and your program's process have each their own current directory).
Read Advanced Linux Programming. It has several chapters related to your issue.
Perhaps you might add some shell function (e.g. into your ~/.bashrc ...) which perhaps could use eval to run your C program (which would output some cd command, that the eval or source builtin of your shell would handle within the same shell process); BTW ssh-agent might be inspirational. Actually I don't recommend this route if you are a newbie.
PS. You really should motivate your question and give a lot more context; it smells badly like an XY problem.

What exactly does the '2' mean when someone writes read(2) while specifying the system call? [duplicate]

This question already has answers here:
What does the number in parentheses shown after Unix command names in manpages mean?
(7 answers)
Closed 6 years ago.
What does someone mean when they say read(2), or open(1)? What do the numbers in the brackets actually mean?
Edit:
Rephrased the title of the question.
The bracket is used to specify the section of man pages. Man pages are organized into different sections and that section number specifies what type of "thing" it is. From Wikipedia, a common organization of sections(on Research Unix, BSD, OS X and Linux) is like this:
1 General commands
2 System calls
3 Library functions, covering in particular the C standard library
4 Special files (usually devices, those found in /dev) and drivers
5 File formats and conventions
6 Games and screensavers
7 Miscellanea
8 System administration commands and daemons
For example, by read(2) it meant it is talking about OS system call read.
They are the man page section identifiers. you should try
man 2 read
or
man 1 open
to see specific versions of those identifiers.

Platform independent method to access command line in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
On windows, the programmer could do something like: system("ls > outputFile.txt")
Is there a platform independent way to access the command line, or a least a way to determine which platform the program is being executed on (because calls for the same functionality vary quite a bit)?
The system(3) function is standard ANSI C, it's already platform-independent. Any conforming C implementation will allow you to call it to run the system default command line processor/shell application. Of course, the actual programs you can run will vary from system to system (e.g. dir only works on Windows, while ls usually works on Unix-like platforms).
system() itself is a standard C function defined in stdlib.h. The way it interprets its argument, though, is not standard (e.g. ls in UNIX, dir in Windows/DOS, etc.). If you're really asking whether there's a platform-independent way to list the files in a directory, the answer is (unfortunately) no. Some libraries do provide portable (to some degree) implementations, most notably Boost: How can I get the list of files in a directory using C or C++?

How to see souce code of Compiled C code in R [duplicate]

This question already has answers here:
How can I view the source code for a function?
(13 answers)
Closed 9 years ago.
I would like to how to view source code of compiled C code in R.
I am looking for C code for package "nlm"; the corresponding compiled C code is "C_nlm".
I am new to R, so please suggest your inputs in a basic way.
Thanks
Take a look here in this R News article about sources
Also some googling around, I found references that the functionality you are looking for is in:
src/main/optimize.c

Resources