Saturday 18 December 2010

Algorithm for To reverse the first n characters in afile

Description:

This program perform the reverse operation of n characters in the file

Algorithm:



Step 1: Star
Step 2: read the command line arguments
Step 3: check if arguments=3 or not

If not print  invalid no of arguments
Step 4: open source file in read mode

Step 5: if NULL pointer, then print file can not be open
Step 6: Store no of chars to reverse in k
K= *argv[2]-48
Step 7: read the item from file stream using fread
Step 8: Store chars from last position to initial position in another
  string(temp)
Step 9: print the temp string
Step 10: Stop

Output:


source.c
this is source ouput.c

Command line arguments source.c    ouput.c

source.c
this is source text
output.c
this is source text

Command line arguments source.c
Invalid number of arguments.

Conclusion: the program is error free


VIVA QUESTIONS:


1) List out the file handling functions ?
Ans: fopen(), fprintf(),fclose(),fscanf(),fgetc(),fputc(), etc..,

2) What is the use of fseek() function ?
Ans: The function fseek sets the file pointer associated with a stream to a new position

3) What is use of the fflush() function ?
Ans: If the given stream has a buffered output, fflush writes the output of the stream to the associate file.

No comments:

Post a Comment