Hi ,
i have read that new line character gets converted to \r\n when writing characters to a file
and converted to new line again when reading.
but i observed one thing here.
i have written contents hello followed by return key .
and i have written a program to count the no of characters i got the result as 7.
then i tried printing character and its ascii value then its printing two characters with the same ascii value( 10 ) at the end . that mean its not converting \r\n to \n . if so the out put should be 6.
this is the program:
#include<stdio.h>
int main(int argc,char *argv[]) {
FILE *fp;
char ch;
int nc=0;
fp=fopen(argv[1],"r");
if(!fp)
printf("file doesnot exist\n");
else {
while((ch=fgetc(fp))!=EOF)
{
printf(" < %c > and < %d > \n", ch , ch );
nc++;
}
printf("no of chars=%d",nc);
}
return 0;
}
i many of the forums many ppl mentioned that there is no difference between text and binary on *nix systems.
the out put i got is:
< h > and < 104 >
< e > and < 101 >
< l > and < 108 >
< l > and < 108 >
< o > and < 111 >
<
> and < 10 >
<
> and < 10 >
no of chars=7
i am running programs on ubuntu 9.04
please help..