simple program
-
Why does this program crush?, what have i left?
#include "stdio.h" int main(int argc, char* argv[]) { FILE* fp; char fname[10]; printf("Enter the file name: ",fname); scanf ("%s",fname); if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } return 0; }
oam -
Why does this program crush?, what have i left?
#include "stdio.h" int main(int argc, char* argv[]) { FILE* fp; char fname[10]; printf("Enter the file name: ",fname); scanf ("%s",fname); if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } return 0; }
oamyou never assigned a value to fp. fp = fopen(...); Image Toolkits | Image Processing | Cleek
-
Why does this program crush?, what have i left?
#include "stdio.h" int main(int argc, char* argv[]) { FILE* fp; char fname[10]; printf("Enter the file name: ",fname); scanf ("%s",fname); if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } return 0; }
oammpapeo wrote: if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } it's should be :
fopen(&fname,"wt"); //&fname without quotation marks
if( fp )
{
int i;
for( i=0; i<10; ++i )
fprintf(fp,"Line %d\n",i);
fclose(fp);
} -
mpapeo wrote: if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } it's should be :
fopen(&fname,"wt"); //&fname without quotation marks
if( fp )
{
int i;
for( i=0; i<10; ++i )
fprintf(fp,"Line %d\n",i);
fclose(fp);
}Actually,
**fp =** fopen (...);
, but you probably meant that. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
mpapeo wrote: if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } it's should be :
fopen(&fname,"wt"); //&fname without quotation marks
if( fp )
{
int i;
for( i=0; i<10; ++i )
fprintf(fp,"Line %d\n",i);
fclose(fp);
}Still it crushes oam because i have made the changes you suggested.
#include "stdio.h" int main(int argc, char* argv[]) { FILE* fp; char fname[30]; printf("Enter the file name: ",fname); scanf ("%s",fname); fopen(&fname,"wt"); if( fp ) { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } return 0; }
-
Still it crushes oam because i have made the changes you suggested.
#include "stdio.h" int main(int argc, char* argv[]) { FILE* fp; char fname[30]; printf("Enter the file name: ",fname); scanf ("%s",fname); fopen(&fname,"wt"); if( fp ) { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } return 0; }
-
Actually,
**fp =** fopen (...);
, but you probably meant that. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.comright :doh:
-
Why does this program crush?, what have i left?
#include "stdio.h" int main(int argc, char* argv[]) { FILE* fp; char fname[10]; printf("Enter the file name: ",fname); scanf ("%s",fname); if( fp ) fopen("&fname","wt"); { int i; for( i=0; i<10; ++i ) fprintf(fp,"Line %d\n",i); fclose(fp); } return 0; }
oammpapeo wrote: if( fp ) fopen("&fname","wt"); { Should be:
fp = fopen(fname, "wt");
if (NULL != fp)
{
...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
mpapeo wrote: if( fp ) fopen("&fname","wt"); { Should be:
fp = fopen(fname, "wt");
if (NULL != fp)
{
...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow