Hello,
I did some expiremets with turning numbers with floating point to strings and vice versa,and bumped into something strange,here is the code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main ()
{
double num;
num=310.589;
char buffer [10];
sprintf(buffer,"%f",num);
buffer[7]=NULL;
printf("using &num=\n");
printf((char *)&num);
printf("\nbuffer=\n");
printf(buffer);
printf("\nfragment of buffer=\n");
printf((char *)&buffer[3]);
scanf("%s",buffer);
num=atof(buffer);
num/=2;
printf("\n%lf",num);
_getch();
}
from some reason the folowing line causes a C0000005 exeption(if I understand correctly it means acces violation):
num=atof(buffer);
why does it happen?
p.s.
the intresting part is that when I compile it shows no errors and no warnings,
the problem appears only when I build.