Please help me with this in C.....

I'm trying to write random integers to another file ..

I just don't get it work....

I'm new at this....

So what's wrong here......."maybee everything"..?

I'd be very grateful for help.

Thanks

erwin




.......

FILE *fp;

int numbers[100];

int *pts;

int i = 0;

int t = 0;

pts = &numbers[0];


{

random();

for ( t = 0; t < 100; t++)

numbers[t] = rand() % 255;

}


if ((fp=fopen("c:\test.txt", "w+")) == NULL)

{

fprintf(stderr, "can't open file....!
");

exit(1);

}



for (i = 0 ; i < 100; i++);

fprintf(fp, "%d", numbers[t]);

fclose(fp);



}




Comments

  • Hi!


    Just make 1 change...and your program runs!!!:


    : for (i = 0 ; i < 100; i++);

    : fprintf(fp, "%d", numbers[t]);

    : fclose(fp);


    Just remove the ';' from the fol. line..


    : for (i = 0 ; i < 100; i++)


    ...and hey presto! It works!!

    Good Luck!


  • Hi!


    Make another change on the same line..


    :for (i = 0 ; i < 100; i++);

    :fprintf(fp, "%d", numbers[t]);

    :fclose(fp);


    fprintf(fp, "%d", numbers[i]);

    |


    make 't' to 'i'


    that's all!!

    Bye!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories