can't help it you guys are turning me into a pedant:DQuote:
Originally Posted by Prelude
So as to the problem the op is having. I've been playing around and came up with some code. It seemed to have worked. So in trully annoying style i'll just post the logic here. You guys can let me know if you see anything wrong with my pseucode.The basic idea is to have two files open at the same time. Seems depending on the OS you can have 10 to about 20 files open at the same time.Code:begin:
type_t encrypt(int) //whatever type your return value is
FILE *file1,*file2;
int ltr,code;
open file1 for reading:
do error handling
open file2 for writing:
do error handling
while ( (ltr =fgetc(file1)) !=EOF):
code = encrypt(ltr)
fputc(code,file2)
if (both file1 && file2 are not close):
give error message
remove file1
end
one file is only for reading which contains the original message, the other is for writing.
you might want to make a function to encrypt your data at least for modularity purposes.
once you copied the changed data to the second file, close both files like soand then remove the first file with the original message. Which is obviously not really deleted, simply removed the link to it.Code:if (fclose(file) != 0 || fclose(file2) != 0)
fprintf(stderr,"Error in closing files\n");
Wish i knew more about files right now, but Just started. let me know how it goes. I've done it alright. I'm sure there is an easier way. Like Dave_sinkula's but i don't know that yet. :)