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);
}
}
#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
Post a Comment