Howdy, Stranger!

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

Categories

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!


  • Andre YoungAndre Young USAMember Posts: 0

    ___ | http://forcoder.org | free video tutorials and ebooks about ( MATLAB Assembly Scratch JavaScript Objective-C Swift Go Delphi Ruby C++ Perl Java C Visual Basic .NET PHP PL/SQL Python C# Visual Basic R Rust LabVIEW Alice Apex ML COBOL F# Logo FoxPro Julia Scala Hack Ada VBScript Prolog Transact-SQL SAS Erlang Crystal Clojure Dart Kotlin Fortran ABAP Scheme D Lua Bash Lisp Awk ) ________

Sign In or Register to comment.