Skip to main content

Write a command line program to accept file name followed by a number say N1. Display line N1 in reverse order of its characters.

#include
#include
#include
#include
#include

char buffer[2048];

void readLine(int fd, int LineNo);

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

   int fd,LineNo;
 
   if(argc != 3)
   {
       printf("Enter The Two Argument First File Name And Other Line No..!!");
       exit(0);      
   }
         
   fd = open(argv[1],O_RDONLY);

   if(fd == -1)
   {
       printf("File Is Not Open");
       exit(0);
   }

   LineNo = atoi(argv[2]);

   readLine(fd,LineNo);
}

void readLine(int fd, int LineNo)
{
   int count,i,line=0,t=0,j;
   char Line[100],OneL[100],ch[]= { ' ', ' '};
   while((count = read(fd,buffer,sizeof(buffer))) > 0)
   {
       for (i=0;i < count;i++)
       {
           if(buffer[i] == '\n')
           {
               Line[t++] = '\0';
               t=0;
               strcpy(OneL,Line);
               strcpy(Line,ch);              
               line++;
             
               if(LineNo == line)
               {
                   for(j=strlen(OneL);j>=0;j--)
                   {
                       printf("%c",OneL[j]);
                   }
                   printf("\n");
               }
               else
               {
                   printf("%s\n",OneL);
               }
           }
           else
           {
               Line[t] = buffer[i];
               t++;              
           }
       }
       printf("Total Line is:%d",line);
   }
}

Comments

Popular posts from this blog

Quiz 1 : Mobile Application Development - Android

Download PDF Version From Here   MCQ 1. Select a component which is NOT part of Android architecture. a. Android framework   b. Libraries          c. Linux kernel   d. Android document 2. What is AAPT? a. Android Asset Processing Tool.             b. Android Asset Providing Tool.   c. Android Asset Packaging Tool.             d. Android Asset Packaging Technique 3. Required folder when Android project is created. a. build                 b. build/               c. bin     d. bin/ 4. Adb stands for   A. Android Drive Bridge.                              B. Android Debug Bridge.            C. Android Destroy Bridge.                          D. Android Delete Bridge. 5. Is list data type supported by AIDL? a. Yes    b. No 6. Component which is NOT under the Android application. a. Content providers      b. Resource externalization         c. Applications d. Notifications 7. Language which is supported by Android for application dev

IP Delivery Concept

It is the practice of using the IP, the network address of the connecting computer, whether robot or human, and sending different content based on that. The database used to assist with the process. In the case of geo-targeting: Databases stores various ranges of IP addresses, and indicates where this ranges of IPs are in the world. A geo-targeting script scans the list to see in which country the current IP is located. Programmer can use this value to effect changes in presentation or logic. In the case of cloaking : Databases stores the IP addresses of the various spiders that may hit your site. The cloaking script scans the list to see if the current IP is a spider. The programmer can use this information to effect changes in presentation or logic. Implementations of IP-delivery-based cloaking also look at the User-Agent header of the request. The user agent header is a header sent by both browsers and spiders. But it is not regarded authoritative, bec

Never try to go back and repair the past which is impossible. But be prepared to construct the future which is possible.

Never try to go back and repair the past which is impossible. But be prepared to construct the future which is possible.