read unknown integers from text file

This is a discussion on read unknown integers from text file within the C Programming forums, part of the General Programming Boards category; i have made a small encyption program nothing fancy really. it turns the letters into 6-9 digit long number seperating ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    1

    read unknown integers from text file

    i have made a small encyption program nothing fancy really. it turns the letters into 6-9 digit long number seperating each with a \n

    i now need to read in each numbers so i can reverse the calculation for the decyrpt but cant seem to work out how to read the number from the text file "output.txt" and store ir as an int so i can preform calculation on it.

    i need to do this in c NOT C++ AND NOT C#

    if anyone can help id really appriciate it. i tryed using fgetc and concatonating the chars togethers and atio them but coudnt get it to work.

  2. #2
    Registered User rpbear's Avatar
    Join Date
    Nov 2009
    Posts
    18
    try the code below
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int
    main(){
    	
    	FILE* fin = fopen("d:\\a.txt","r");
    	long ld = 0;
    	
    	while(fscanf(fin,"%ld\n",&ld) == 1)
    		printf("%ld\n",ld);
    	
    	return EXIT_SUCCESS;
    	}

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    At some point, aren't you going to be hexed by the encryption program giving you "numbers" that are preceded by zero's, like: "003569"?

    How are you going to handle it in your program?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [HELP] Read text file in vc++ 2005
    By sonnb in forum C++ Programming
    Replies: 1
    Last Post: 05-12-2007, 11:01 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Replies: 5
    Last Post: 02-01-2003, 10:58 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

Tags for this Thread


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