need help with input and output files ASAP

A

Aalok

This is what i want to do.
Read a text file as an input and based on that file, Create an outpu
text file which saves the contents of the input file in a specifi
format in the output file.

I know how to read a text file and i can even display the contents o
the input file on the prompt. However i am trying to figure out how t
save the contents of the input file in a specific manner.


example.;

this is my input file (say numbers.txt)
1,2,3,4,5,6,7,8,9,10 and data bytes 5.

this is what i want in my output file (outputfile.txt)
10,0,12345678,9abcdef, 1,1, 5,0

my purpose is to create packets from inputs provided.
and feed these packets to a hardware language as an input


-
Aalo
 
T

Tim Hagan

Aalok said:
This is what i want to do.
Read a text file as an input and based on that file, Create an output
text file which saves the contents of the input file in a specific
format in the output file.

I know how to read a text file and i can even display the contents of
the input file on the prompt. However i am trying to figure out how to
save the contents of the input file in a specific manner.


example.;

this is my input file (say numbers.txt)
1,2,3,4,5,6,7,8,9,10 and data bytes 5.

this is what i want in my output file (outputfile.txt)
10,0,12345678,9abcdef, 1,1, 5,0

Huh? How did you derive that from the input text? Never mind. I don't
want to know.
my purpose is to create packets from inputs provided.
and feed these packets to a hardware language as an input.

Figure out how to transform your input text into the required output
format and write it to a file. I can't help you with the first part
but second part is easy:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char *file = "outputfile.txt";
char *text = "10,0,12345678,9abcdef, 1,1, 5,0";
FILE *out;

out = fopen(file, "w");
if (out == NULL)
{
fprintf(stderr, "Can't open '%s' for writing.\n", file);
return EXIT_FAILURE;
}
fprintf(out, "%s\n", text);
fclose(out);
return EXIT_SUCCESS;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top