This question already has an answer here:
How to add, delete edit username from /etc/passwd [duplicate]
(1 answer)
Closed 6 years ago.
I m playing with /etc/passwd in my C program.
I want to change a user password. are there a standard linux functions that do a such functions ?
Method 1: system("passwd <parameters>");
Method 2: *pwent() function family and also putpwent().
The question is possibly a duplicate.
Linux stores the password in the /etc/shadow file. The second column (delimited by : character) in this file against the user name shows the hashed password.
It's best advised to not touch this file and cause harm. If you must, you can use the vipw utility for editing
Related
This question already has answers here:
Stop shell wildcard character expansion?
(4 answers)
Closed 6 years ago.
i'm trying to write code in C,which implements a simple calculator.
the input should come from the command line, so for example i if i run
./calculator 5 * 2
the result should be 10
the problem is that when i write * it shows all the files in the current directory and the program doesnt behave well.
there is anyway to overcome this problem?
i tried to find here or in other sites solutions,without success.
i need that * will Be interpreted as a char and not as a linux command.
thanks.
In linux shell, the * has special meaning. It is meant for globbing unless it is quoted like below
./calculator 5 '*' 2
You may also escape the asterisk to strip the special meaning from it
./calculator 5 \* 2
This question already has answers here:
Hide a file or directory using the Windows API from C
(4 answers)
Closed 8 years ago.
Does anybody know if it is possible to hide files or make them invisible to other users? Or, does creating file in "w" mode achieve invisibility?
Ex:
If I create a file like this:
FILE *fp = fopen("aFile","w");
Can other users on my system read it?
I guess I'm asking for the C way to add access modifiers to files in C, sort of like the chmod command does..
It is not possible to set access permission when using fopen.
Use CreateFile instead to open file and set access permissions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using following code to create a new file cat15 using cat command in UNIX
# cat > cat15
this command adds a new file cat15 in root directory and whatever I type after this command is being stored into the file created. But I am not able to exit from this editor.
In other word, I am not getting Shell prompt symbol #
The cat command reads from STDIN if you don't specify a filename. It continues to do this until it receives an EOF or is killed. You can send an EOF and get your terminal back by typing <ctrl>+d.
What people generally do is to either use
touch filename
or
echo -n > filename
to create an empty file. As Charles correctly notes below, "echo -n" is not always a good idea (though you can usually count on it under "popular" Linux distros); I'd strongly suggest just using touch.
If you just want to create an empty file, regardless of whether one existed or not, you can just use ">" like this:
> cat15
It will clobber anything that already exists by that name.
This question already has answers here:
Problem redirecting a C program output in bash
(5 answers)
Closed 9 years ago.
So this is probably a stupid question, but I can't see what I'm doing wrong.
I am running a program that produces output when called like ./ar. The output looks like:
-0.00781 0.02344 0.98828
-0.01172 0.02734 0.98828
-0.01562 0.02344 0.98047
-0.00781 0.02344 1.00000
-0.00391 0.02344 0.98438
A new line of output is written every second.
When I call the code like this ./ar > log and kill the program using ctrl-c after a few seconds, the file log is empty.
I am running this code on an embedded system. The system has a writeable partition which is the partition that I am running in, and I have write access as I am logged in as root.
The reason is the lazy writing concept of UNIX system.
Are you sure you are looking at standard output in you call ./ar? It might be standard error.
So, try ./ar >log 2>err to have 2 files, one for stdout and one for stderr.
Or use ./ar 2>&1 >log to get one file for both streams.
This question already has answers here:
Reading a text file backwards in C
(5 answers)
Closed 8 years ago.
I am trying to implement a shell in C. Here's the thing. I want to make a history friendly function where if I press up it goes to prev. command.
Now I have a file which stores the history, say history.txt. When I execute a command, I would append the command to the text. And resets an offset of some sort to the last line of the file.
I need a way to find the last line and move up a line one by one on command. AND move up one by one on command.
Right now, an idea I have is to fgets() till -1 or something?
Any ideas for how I should start?
edit: I can think of a solution using an Array. But is there a way where I use little to no space?
Don't bother reading history from the file when you need to run the previous command. Just store the previous commands in memory. Write them to disk on exit, and load them on startup. That's sort of how real shells work.