I have put together this program that seems to do what I want without
error checking added yet. If I just run the program it produces a
segmentation fault. If I add the proper value say 43.56 it's fine. Does
anyone see what's wrong ? I have a c99 compiler. Thanks.
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] ) {
FILE*fp;
double x;
x=strtod(argv[1],NULL);
if (argc !=2) {
fprintf(stderr, "usage error\n");
exit(EXIT_FAILU RE);
}
fp=fopen( "data", "a");
ftell(fp);
fseek(fp,sizeof (double),SEEK_C UR);
fprintf(fp,"%.2 f\n",x);
fclose(fp);
}
error checking added yet. If I just run the program it produces a
segmentation fault. If I add the proper value say 43.56 it's fine. Does
anyone see what's wrong ? I have a c99 compiler. Thanks.
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] ) {
FILE*fp;
double x;
x=strtod(argv[1],NULL);
if (argc !=2) {
fprintf(stderr, "usage error\n");
exit(EXIT_FAILU RE);
}
fp=fopen( "data", "a");
ftell(fp);
fseek(fp,sizeof (double),SEEK_C UR);
fprintf(fp,"%.2 f\n",x);
fclose(fp);
}
Comment