How to store a File content in a variable using C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anitha1234
    New Member
    • Oct 2006
    • 8

    How to store a File content in a variable using C

    Hi

    I have generated one file ( this file contains only random numbers in binary form)
    now i have to pass the content of file into some function,
    so i want to store my content of file into a variable. file size may vary,
    how to do this, pls help me.

    Thanks
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by anitha1234
    Hi

    I have generated one file ( this file contains only random numbers in binary form)
    now i have to pass the content of file into some function,
    so i want to store my content of file into a variable. file size may vary,
    how to do this, pls help me.

    Thanks
    in C++ you could read the values into a vector and pass that to the function, e.g.
    http://www.cppreferenc e.com/cppvector/index.html

    in C you could use an array - you would need to determine the amount of data then malloc() storage for it
    http://www.codeproject .com/tips/newandmalloc.as p

    Comment

    Working...