CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
Write a program which accepts a filename as a command line argument and reverses the contents of the file( ie first character

becomes the last character of the file and so on)


Input: The program takes the file name whose content should be reversed.

Output: The program reverses the contents of the file.




Category C Interview Questions
Rating (0.0) By 0 users
Added on 7/17/2006
Views 715
Rate it!
Answers:

#include #include int main(int argc, char *argv[]){ int fd, i, fsize; char *first=(char *) malloc(1); char *last=(char *) malloc(1); if (argc != 2) { printf("pass two argumentsn"); exit (-1); } /* Open the file */ fd = open(argv[1], O_RDWR); if (fd == -1) { printf("error in file openingn"); exit (-1); }#ifdef PRINT printf("File Open Sucessn");#endif /* Find the file size */ fsize = lseek(fd, 0, SEEK_END);#ifdef PRINT printf("File Size = %dn", fsize);#endif /* Reverse the file */ for (i=0; i



#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>

int main()
{
int fd=0,i=0,len=0;
char buf[100];
fd=open("file.txt",O_RDONLY);

read(fd,buf,sizeof(buf));
len=strlen(buf);

for(i=len;i>=0;--i)
printf("%c",buf[i]);
printf(" ");

}



 Posted by: anoj    

Contact anoj  Contact anoj


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
How to type a string without using printf function?

View Answer
Whats is structure padding?Say a given structure
Struct{
int a;
char c;
float d;
}
the size of structure is 7 here.
But structure padding is done what will be the size of the struct?Will it change and how?How to avoid this?is it necessary?

View Answer
When is a switch statement better than multiple if statements?
View Answer
What is the difference between goto and longjmp() and setjmp()?
View Answer
What is an lvalue?
View Answer
Array is an lvalue or not?
View Answer
What is page thrashing?
View Answer
What is a const pointer?
View Answer
When should the register modifier be used? Does it really help?
View Answer
when should the volatile modifier be used?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/5941/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.84