answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <conio.h>

#include <string.h>

#include <process.h>

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

{

char a[15];

char s[20];

char n;

int k;

int j=0;

int i;

int len;

FILE *fp;

if(argc!=3)

{

puts("Improper number of arguments.");

exit(0);

}

fp = fopen(argv[1],"r");

if(fp == NULL)

{

puts("File cannot be opened.");

exit(0);

}

k=*argv[2]-48;

n = fread(a,1,k,fp);

a[n]='\0';

len=strlen(a);

for(i=len-1;i>=0;i--)

{

s[j]=a[i];

printf("%c",s[j]);

j=j+1;

}

s[j+1]='\0';

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

#include<stdio.h>

#include<assert.h>

int main (void) {

FILE* pf;

int i, j, count;

char file[255];

char* buf;

while (true) {

printf ("File name: ");

scanf ("%s", file);

if (pf=fopen (file, "br+")) break;

printf ("Invalid file name\n");

}

while (true) {

printf ("Count of bytes to swap: ");

scanf ("%d", &count);

if (count<1) {

printf ("Count must be greater than 0\n");

continue;

}

buf = malloc (count * sizeof (char));

if (fread (buf, 1, count, pf)==count) break;

free (buf);

fseek (pf, 0, SEEK_SET);

printf ("The file doesn't contain enough bytes to swap\n");

}

assert (pf);

assert (buf);

i=-1, j=count;

while (--i<--j) swap (buf[i], buf[j]);

fseek (pf, 0, SEEK_SET);

fwrite (buf, 1, count, pf);

fclose (f);

free (buf);

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How will be the c program for reversing first n characters in a file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a file that is the last 3 characters that follow the file name that identify the type of program used to create the file?

The file extension. It comes after the file nice, after the last dot in the name. For example someTextDocumet.txt has the extension TXT for plain text. The program that created it is most likely the default one for opening it.


How do you remove a dll file that is open by other programs?

You have to close the other program first, because when a program has a file open, the system locks the file.


What piggyback upgrade?

It means a file or program is attached to another file or program, so that when the first file or program is run or moved then attaduded to it also , the first file or program takes the one attached to it along for the ride, like giving a biggy hence the term.


What is an unsupported file type?

Unsupported file types are file extensions that Windows does not know what to do with. This means that there is no program installed on the computer associated with a particular file type. To open an unsupported file type you must first install the program that the file uses to work with it.


How do you add a program to a file folder?

How do you add a program to a file folder?


Is the last 3 characters that follow the file name that identify the type of program used to create the file?

Yes. If the file ends with .zip, it is a ZIP Archive file. There is a way to change the extension, however, using an extension changer found on the internet. The filename extension (characters to the right of the dot in the file name) identifies the type of file (unless this extension is renamed by a computer user) in most cases. The type of file will identify what can use or open the file, but not necessarily what created the file.


What are the characters that follow a file name?

Things like ( .doc .exe .jpg .gif .xls ) are called file extensions. They tell the operating system which program to use in order to read/understand the data contained in the file. For instance if you were to try to open a file named "My_term_paper.doc" the computer would see the .doc and know to open your chosen word processing program.


How many characters can be in a file name using Windows 95?

Windows 95 supported file names up to 255 characters in length.


Looking at a program file name and file extension how can you tell if the program?

Files are named in the method: filename.extension When the file is a program, the extension is 'exe' so if a file called 'hello' was a program, it would be called: hello.exe


What are the three or four characters right of the period in a file name where the file can be hidden or displayed?

That is the file extension. Each file has this extension to tell the system what to do with the file. For example, a program has .exe at the end. This means that it is an executable file, so the system will launch it as a standard executable. A document has .doc or .docx. The system checks file association when you run it, and tells whatever program is set to handle documents to open that file. If you have MS Word, then it will open the file. If you use Open Office, then that program will open it. If you change the extension, then a different program will try to open the file. For example, changing a .jpg to a .txt will open notepad. However, the file is not actually plain text, so you will see many pages of gibberish, since notepad doesn't really know what to do with the image file.


How do you transfer a HTML file to the internet?

First you have to have a File Server or a Host that will allow you to upload your file. Then you can use a type of program that is known as a "File Transfer Protocol" software. This program will log-in to the Host's File Server and locate the appropriate folder and move the program for you. You can search the internet and find free FTP software to do this. BUT you have to have a website to upload the file to. You can register for a website NAME. You can do this yourself or some places will do this for you and then rent you the file server space for your files.


What is the unix command to display the first two characters of all the lines from a file?

Assuming that the file you are looking at is a columnar file you can use the 'cut' command, as in 'cut -c1-2 filename'