Question:
Can you write a program to intercange two value using command line argument in unix shell programming?
Deepak Raj
2010-09-22 01:31:49 UTC
Tere are two questions
1.write a program to intercange two value using command line argument in unix shell programming
2.write a program to compare two number/string using command line argument in unix shell programming.
Three answers:
2010-09-22 01:55:24 UTC
I believe you are wrong, good sir. There are three questions. The first is hidden deep. Without the first these two are meaningless for you will never have the answer to either unless the first is answered. Begin the search, young friend.
jplatt39
2010-09-22 03:44:19 UTC
In general there are some basic environmental variables. There is $HOME of course which is your home directory and $PATH which is where the shell looks for executable files, but when you type a command line, $0 is the first string typed on that line -- usually the name of the program you want to run, $1 is the second string, $2 the third string and so forth. So essentially you have to write a script which interchanges the values in $1 and $2 and you have to write a script which compares them. If it's homework we shouldn't do it for you but here is a bash tutorial and you can find plenty of documentation for csh tsh zsh or whatever you are using:



http://www.gnu.org/software/bash/manual/bashref.html
?
2016-06-02 09:22:17 UTC
doesn't exist in C, only c++. Besides, if you were doing C++, you'd use std::string and just use the + operator defined on them to concatenate. You want string.h. #include #include int main(int argc, char** argv) { if(argc != 3) { printf("Give me two strings to concatenate\n"); return 1; } // Silly way printf("%s%s\n", argv[1], argv[2]); // ok they're concatenated. // way probably desired. char* newstring = malloc(strlen(argv[1]) + strlen(argv[2]) + 1); strcpy(newstring, argv[1]); strcat(newstring, argv[2]); printf(%s\n", newstring); free(newstring); return 0; }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...