Thread: Reading large number from file

  1. #1
    Join Date
    Mar 2005

    Reading large number from file

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


    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)

    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);	

  2. #2
    The larch
    Join Date
    May 2006
    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
    The edge of the known universe
    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.

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, 03:44 PM
  2. Reading integers from a File into an Array
    By bobby19 in forum C Programming
    Replies: 13
    Last Post: 10-09-2006, 01:36 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08: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