Howdy, Stranger!

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

Categories

Filestream Data to Int

VelduangaVelduanga Member Posts: 5
I have a file with numbers in it. What do I do to to use a file stream that takes the numbers as INTs not CHARs. I keep getting a type cast error if I .get a variable INT.

Comments

  • VelduangaVelduanga Member Posts: 5
    : I have a file with numbers in it. What do I do to to use a file stream that takes the numbers as INTs not CHARs. I keep getting a type cast error if I .get a variable INT.
    :
    Also, how can I pass an Array as a Function parameter properly?
  • rbarreirarbarreira Member Posts: 22
    Have you tried using:

    int a;
    fscanf (file, "%d", &a);

    This skips all whitespace (spaces, newlines, tabs) and reads the next integer from a text file...

    Be more specific in your second question please...

    : : I have a file with numbers in it. What do I do to to use a file stream that takes the numbers as INTs not CHARs. I keep getting a type cast error if I .get a variable INT.
    : :
    : Also, how can I pass an Array as a Function parameter properly?
    :

  • VelduangaVelduanga Member Posts: 5

    : Have you tried using:
    OK say I read the data then I want to send the entire array of that data into another function. I'm not quite sure how to do that. Thanx
    :
    : int a;
    : fscanf (file, "%d", &a);
    :
    : This skips all whitespace (spaces, newlines, tabs) and reads the next integer from a text file...
    :
    : Be more specific in your second question please...
    :
    : : : I have a file with numbers in it. What do I do to to use a file stream that takes the numbers as INTs not CHARs. I keep getting a type cast error if I .get a variable INT.
    : : :
    : : Also, how can I pass an Array as a Function parameter properly?
    : :
    :
    :

  • VelduangaVelduanga Member Posts: 5
    Which Library is fscanf in?
    : OK say I read the data then I want to send the entire array of that data into another function. I'm not quite sure how to do that. Thanx
    :
    : : Have you tried using:
    : :
    : : int a;
    : : fscanf (file, "%d", &a);
    : :
    : : This skips all whitespace (spaces, newlines, tabs) and reads the next integer from a text file...
    : :
    : : Be more specific in your second question please...
    : :
    : : : : I have a file with numbers in it. What do I do to to use a file stream that takes the numbers as INTs not CHARs. I keep getting a type cast error if I .get a variable INT.
    : : : :
    : : : Also, how can I pass an Array as a Function parameter properly?
    : : :
    : :
    : :
    :
    :

  • rbarreirarbarreira Member Posts: 22
    fscanf is on stdio.h

    About the array question:

    Suppose you wanted to make a function to print the contents of an int vector. The function would be like this:

    // the next line could also be:
    // void print_int_vector (int *vector, int n_elements)
    // it's exactly the same
    void print_int_vector (int vector[], int n_elements)
    {
    int loop;

    for (loop=0; loop < n_elements; loop++) { // loop through each element
    printf ("%d ", vector[loop]); // print one more element
    }
    printf ("
    "); // end of the vector, advance one line...
    }

    Now suppose that in another function you had a vector like:
    int my_vector[100];

    If you want to print it's contents using the function I showed you, you do this:
    print_int_vector (my_vector, 100);

    my_vector could also be a pointer to the first element in a vector...

    I hope this is enough,
    Ricardo
    : Which Library is fscanf in?
    : : OK say I read the data then I want to send the entire array of that data into another function. I'm not quite sure how to do that. Thanx
    : :
    : : : Have you tried using:
    : : :
    : : : int a;
    : : : fscanf (file, "%d", &a);
    : : :
    : : : This skips all whitespace (spaces, newlines, tabs) and reads the next integer from a text file...
    : : :
    : : : Be more specific in your second question please...
    : : :
    : : : : : I have a file with numbers in it. What do I do to to use a file stream that takes the numbers as INTs not CHARs. I keep getting a type cast error if I .get a variable INT.
    : : : : :
    : : : : Also, how can I pass an Array as a Function parameter properly?
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

  • Shawn CarterShawn Carter Member Posts: 0

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

Sign In or Register to comment.