Filestream Data to Int

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

  • : 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?
  • 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?
    :


  • : 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?
    : :
    :
    :

  • 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?
    : : :
    : :
    : :
    :
    :

  • 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?
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :

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