Parsing and Fwrite Help Please.
Hey peoples...
This is a little program i use frequently..
But i need it to add further function.
At the moment, it prints the correct numbers
to a console window.
But XPPro ........s itself everytime i try and cut and paste from that window to a text file..... (works maybe 40% of the time)
So i'd like to add two things to this code...
It needs to write the numbers to a text file (rather than to screen) can i just change the last printf to fwrite test.txt
or something...
I also want to add a comma after every number....
for example.. (like parsing in my original script version)
so i can use the resulting numbers in a array.
Code:
#include <stdio.h>
#define MAX_LINE_LEN 256
#define BYTES_PER_LINE 16
main (argc,argv)int argc;char* argv[];
{
char filename [MAX_LINE_LEN];
FILE *file;
char bytes[BYTES_PER_LINE];
int i, j;
int filename_provided=0;
int filesize;
int bytes_read=0;
long pos=0L;
int data_only=0;
int Dunno_X=0;
{
if (!strcmp(argv[1],"-d")) {data_only=1;}strcpy(filename,argv[2]); filename_provided=1;}
if (filename_provided)file=fopen(filename,"rb");/* Open the input file */ {}{{}}
while (!feof(file)){bytes_read=fread(bytes,1,BYTES_PER_LINE,file);
for (i=0; i<BYTES_PER_LINE; i++){
if (file == stdin) /* If the value is stdin, we require special processing */ {{
if (data_only){}
else{}}}{
if((i<bytes_read) && ((filesize-1) != (pos-bytes_read+i))){
if (Dunno_X) {}
else {printf("%02d ",bytes[i] &0xff);}}
else {}{}}
if (!data_only) {}}{}
printf("\n"); }
fclose(file);
return 0;}
And no this is not homework...
So at the moment i use the console.
Numbers -d test.ixm
70 79 82 77 00 00 17 114 76 87 79 50 84 65 71 83
00 00 00 18 70 108 111 111 114 00 84 104 117 110 100 101
So i'd like it to look like this......
70, 79, 82, 77, 00, 00, 17, 114, 76, 87, 79, 50, 84, 65, 71, 83,
00, 00, 00, 18, 70, 108, 111, 111, 114, 00, 84, 104, 117, 110, 100, 101
And then have them in a .txt file instead of the console...
Any help, on making that happen is appreciated.
Thanks again..
Cheers,
Scott.