c - What is wrong with my .dat file -


my code takes string, writes in .dat file , reads .dat file , posts in console.

my problem .dat know should coded, , couldn't open , see what's there. when open d.at file notepad, behaves same .txt file , can see it's written.

   #include <stdio.h> #include <stdlib.h>  int main() {     file *f;     char s[100],g[100];      if((f=fopen("text.dat","wb"))==null)     {         exit(1);     }     printf("write text: "); gets(s);     int n=strlen(s);     fwrite(s,sizeof(s[0]),n,f);     fclose (f);     if((f=fopen("text.dat","rb"))==null)     {         exit(1);     }     fread(g,sizeof(g[0]),strlen(s),f);     puts(g);     return 0; } 

nothing wrong .dat file.

my problem .dat know should coded

what coded mean? changing file extension .txt .dat doesn't make difference, in fact it's renaming it. microsoft windows or other os may open specific file types specific programs default, doesn't mean can't use program of choice. in case, notepad read file contents, characters read keyboard , written it, without "coding" (except ascii encoding of course).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -