Reading large number from file

This is a discussion on Reading large number from file within the C++ Programming forums, part of the General Programming Boards category; please delete this .. i put it in the wrong forum. sorry hi, Im trying to read a large number ...

  1. #1
    Waxy-Dock
    Join Date
    Mar 2005
    Posts
    69

    Reading large number from file

    please delete this .. i put it in the wrong forum. sorry

    hi,

    Im trying to read a large number from a file, into a variable and then print it.

    This is what i have tried, but i am getting a seg. fault. (ive attached the file as well)

    Code:
    long current;
    FILE *inFile;
    
    if (!(inFile = fopen("tests/100.tst","r")))
    	fprintf(stderr, "tests/100.tst cannot be opened!\n");
    	
    else {
    	fscanf(inFile, "%d", &current);
    	printf ("\n%d\n", current);	
    }
    Attached Files Attached Files

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    This won't fit into any integral type (long). You'll need to treat it as a string (or array of characters).

    (Your format flag - d - is also wrong, I guess.)

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,769
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  2. Reading integers from a File into an Array
    By bobby19 in forum C Programming
    Replies: 13
    Last Post: 10-09-2006, 02:36 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21