LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2002, 09:45 AM   #1
tyler_durden
Member
 
Registered: May 2001
Posts: 125

Rep: Reputation: 15
Writing encrytped data to a disk


I am writing a program that writes encrypted data to a file. i am worried that one of the encrypted strings might carry the EOF charachter in it and prematurely end the file. Is there a way i can avoid this? thank you
 
Old 04-13-2002, 05:48 PM   #2
rstrong
LQ Newbie
 
Registered: Apr 2002
Posts: 2

Rep: Reputation: 0
Thumbs up No Problem

The EOF character is only a reading concept for some file input fuctions which return characters one at a time. For instance if you use fgetc and it returns you the EOF character, you might be at the end of the file but you will not know until you check with a call to feof. Reading EOF from a file is not a problem when using functions like fread, it's just another character.

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

int main()
{
char buff[100] = { '\0' };
FILE *fp;
fp = fopen("blahblah","w");
fprintf(fp,"Hello%c World\n",EOF);
fclose(fp);
fp = fopen("blahblah");
fread(buff,1,100,fp);
printf("%s",buff);
fclose(fp);
}
 
Old 04-17-2002, 11:18 PM   #3
zmedico
Member
 
Registered: Feb 2002
Location: Mission Viejo, California, USA
Distribution: Gentoo
Posts: 707

Rep: Reputation: 30
The filesystem knows where EOF is based on the *length* of the file, not on data inside the file.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
writing raw data to a tiff file James_dean Programming 4 10-25-2005 05:03 AM
writing encrypted data to disk rblampain Linux - Security 14 07-31-2005 11:38 PM
Error 5 in Kb3 writing Windows Data Chems Linux - Newbie 1 09-11-2004 10:34 AM
CD RW -- Writing Data to CD dnachtwey Linux - Hardware 39 01-25-2004 06:22 PM
perl - writing a data structure to a file.. is it possible? paavaka Programming 4 07-14-2001 12:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration