Filing in C

7 views
Skip to first unread message

madeelch

unread,
Aug 2, 2007, 9:10:45 AM8/2/07
to KUDCS
how do u tackle unicodes and special characters [example (alt +254)
onwards ] etc while making a copy of one file to another file .... by
using filing ??
when i tried to do it by reading characters one by one and riting them
to a new file i got new lines where thr were specials characters and
some times nothing ....


i'd b lookin forward for the answers

Rizwan Zahid

unread,
Aug 3, 2007, 4:01:15 AM8/3/07
to ku...@googlegroups.com
AOA!
        send the code how you are doing ? try this function
 
#define  COPY_OK   1
#define COPY_ERROR -1
 
int FileCopy
  ( const char *src,
    const char *dst )
{
#define BUFSZ 16000

char            *buf;
FILE            *fi;
FILE            *fo;
unsigned        amount;
unsigned        written;
int             result;

buf = new char[ BUFSZ];

fi = fopen( src, "rb" ) ;
fo = fopen( dst, "wb" );

result = COPY_OK;
if  ((fi == NULL) || (fo == NULL) )
  {
  result = COPY_ERROR;
  if (fi != NULL) fclose(fi);
  if (fo != NULL) fclose(fo );
  }

if (result == COPY_OK)
  {
  do
    {
    amount = fread( buf, sizeof(char), BUFSZ, fi );
    if (amount)
      {
      written = fwrite( buf, sizeof(char), amount, fo );
      if (written != amount)
        {
        result = COPY_ERROR; // out of disk space or some other disk err?
        }
      }
    } // when amount read is < BUFSZ, copy is done
  while ((result == COPY_OK ) && (amount == BUFSZ));
  fclose (fi);
  fclose(fo);
  }
delete [] buf;
return(result);
}
 
Hope it will work ,
 
Take Care

ChaudhrY

unread,
Aug 3, 2007, 4:05:36 AM8/3/07
to ku...@googlegroups.com
W/s
the thing is ... i dont wana do it in binary mode ...............
i wana edit the file as well ..

Rizwan Zahid <rizc...@gmail.com> wrote:
ChaudhrY

Send instant messages to your online friends http://uk.messenger.yahoo.com

Rizwan Zahid

unread,
Aug 3, 2007, 4:20:17 AM8/3/07
to ku...@googlegroups.com
This will be done in the same way make a copy of Edit buffer and pass it to file write func
 
written = fwrite( buf, sizeof(char ), amount, fo );
 
buf contain the edit data  as simple as that !

 
    amount = fread ( buf, sizeof(char), BUFSZ, fi );
    if (amount)
      {
      written = fwrite ( buf, sizeof(char), amount, fo );

      if (written != amount)
        {
        result = COPY_ERROR; // out of disk space or some other disk err?
        }
      }
    } // when amount read is < BUFSZ, copy is done
  while ((result == COPY_OK ) && (amount == BUFSZ));
  fclose (fi);
  fclose(fo);
  }
delete [] buf;
return(result );
}
 
Hope it will work ,
 
Take Care
 
 
 
 
             

 
On 8/2/07, madeelch <made...@yahoo.com> wrote:

how do u tackle unicodes and special characters [example (alt +254)
onwards ] etc while making a copy of one file to another file .... by
using filing ??
when i tried to do it by reading characters one by one and riting them
to a new file i got new lines where thr were specials characters and
some times nothing ....


i'd b lookin forward for the answers





 
Reply all
Reply to author
Forward
0 new messages