putc in c programming in files -


im creating own library on file handling make more flexible,but got stucked @ these point watch these below program

int filewrite(char *filename,unsigned char number) {     file *dill;      if((dill=fopen(filename,"r"))==0)         return(0);// error no such file exists  returns 0     else     {          if(number==0)         {             dill=fopen(filename,"w");              while(number!='x')             {                 number=getche();                 putc(number,dill);             }         }         else         {             dill=fopen(filename,"a+");              while(number!='x')             {                 number=getche();                 putc(number,dill);             }         }     } } 

for instance made condition not equal x if enter x letter gets terminated, want used too.but condition put use letters numbers , special symbols when writing file becuase if hit enter goes next line not terminating , want use enter how eof using putc ? me guys

if want terminate when press enter can change while loop this:

while((number != 'x') && (number != '\r')) {     number=getche();     putc(number,dill); } 

you should close file pointers using fclose(dill) make sure stream flushed , files aren't left opened when program terminates.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -