Skip to main content

Searching using system calls Program in C Code

Write a C program that takes a file name as a command line parameter and sorts a set of integers stored in the file (use any sorting method). You can assume that the file will always be there in the current directory and that it will always contain a set of integers(maximum no. of integers is 1000). The sorted output is written to the display and the input file is left unchanged. Compile the C file into an executable named “sort1″. Now write a C program that implements a command called “sort” that you will invoke from the shell prompt. The syntax of the command is “sort “. When you type the command, the command opens a new xterm window, and then sorts the integers stored in the file using the program “sort1″. Look up the man pages for xterm, fork and the different variations of exec* calls (such as execv, execve, execlp etc.) to do this assignment.


int main(int argc, char *argv[])

FILE *fp1;
int A[1000],T[1000];
int j,i=0;

/* check that we have a file name specified as a command-line argument */
if (argc<2)
printf(“\nPlease enter filename as argument when running this program.\n”);
printf(“For example: listprog file.txt\n\n”);
return -1;

fp1= fopen(argv[1], “r”);
if (!fp1)
printf(“\nUnable to open file: %s; exiting.\n\n”, argv[1]);
return -2;

for(j=0;(j<1000)&&(feof(fp1)== 0);j++)
if(feof(fp1)== 0)


return 0;

display(int A[],int n)
int i;


sort(int a[],int n)
int i,j,t;





Popular posts from this blog


Agricultural Research Service

Eligibility Test/ Senior Research Fellowship Examination 

The Agricultural Scientists Recruitment Board (ASRB)
 holds a Competitive Examination for recruiting Scientists of the ARS in the pay scale of Rs. 8,000-13,500 in the ICAR Institutes, combined with National Eligibility Test (NET) for recruitment of Lecturers and Assistant Professors by the State Agricultural Universities (SAUS) and for award of ICAR Senior Research Fellowships.

The selected candidates for Agricultural Research Service must serve in the institutes to which they are posted until they find appointment for higher positions through selection at other institutes.

(i) Candidates successful in ARS are appointed as Scientists in the Indian Council of Agricultural Research in the pay scale of Rs. 8,000-13,500.

(ii) Candidates clearing the National Eligibility Test are recommended to various State Agricultural Universities who will consider them for appointment as Lecturers or Assistant Pro…


The Union Public Service Commission (U.P.S.C.) conducts Civil Services' Examination once a year in two stages. The Preliminary Examination (Objective Type) for selection of candidates for the Main Examination is held in the month of May.

The Civil Services Main Examination
 is held in the months of October/November. Blank application forms and other particulars are published in the Employment News, generally in the month of December.

The last date for the submission of applications to the Secretary, Union Public Service Commission, Dholpur House, Shahjahan Road, NewDelhi-11001 1 is usually the last week of January of the year of examination.

The Combined Civil Services Examination is conducted for Recruitment to the following Services/Posts:

1. Indian Administrative Service.
2. Indian Foreign Service.
3. Indian Police Service.
4. Indian P & T Accounts & Finance Service, Group 'A'.
5. Indian Audit and Accounts Service, Group 'A'.
6. Indian Customs and Central Excise S…

Aptitude Test Practice Questions - With Answers

Question 1. Which of the following is least like the others?
A.    cube
B.    sphere
C.    pyramid
D.    circle

D (because the circle is the only two-dimensional figure)

Question 2. Consider a language which uses the following set of characters:
Small set: { a b c }
Large set: { A B C }
Punctuation set: { x y }
This language must follow the following rules:
  1.    A punctuation character must end all series.
  2.    A series can have up to but no more than 4          characters,including punctuation characters.

Does the following series follow all the rules of the language defined above?
  A.    Yes
  B.    No

A (the series has only four characters and ends in a punctuation character)

Question 3. Consider the following flow chart for a customer:

The person in No.1 is:
    A.   Married, with children
    B.   Married, with at least one son
    C.   Unmarried, with at least one daughter
    D.   Unmarried, with at least one son
    E.   Unmarried, with no children