Thread: File io

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    17

    File io

    I have a quick question

    How would i read in these numbers

    Code:
    1234,2345,3456,4568
    from a .txt file without the commas?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Teardrop3903 View Post
    I have a quick question

    How would i read in these numbers

    Code:
    1234,2345,3456,4568
    from a .txt file without the commas?
    Code:
    int a,b,c,d;
    
    fscanf("%d,%d,%d,%d",&a,&b,&c,&d);

  3. #3
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    17
    Can i just do this?

    Code:
    fscanf("%d,", &a);
    and have a loop to keep on reading?

    something like this

    Code:
    while ( (fscanf(id, "%d,", &existId)) != EOF)
    	{
    		if(existId == userId)
    		{
    			printf ("Login Success\n");
    			return VALID;
    		}
    	}
    In this case I'm comparing the read in ID to another ID that a user inputed

    Quote Originally Posted by Mr.777 View Post
    sorry i should have said it earlier but i'm trying to identify each ID in a loop so i don't have to create so many variables.

    I have looked in my text book but nothing mentions how i can do this. That is why i'm on the cboard.
    Last edited by Teardrop3903; 03-10-2011 at 08:39 AM.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Teardrop3903 View Post
    Can i just do this?

    Code:
    fscanf("%d,", &a);
    and have a loop to keep on reading?

    something like this

    Code:
    while ( (fscanf(id, "%d,", &existId)) != EOF)
    	{
    		if(existId == userId)
    		{
    			printf ("Login Success\n");
    			return VALID;
    		}
    	}
    In this case I'm comparing the read in ID to another ID that a user inputed
    Yep, you can do that too...
    But if you already knew how you wanted to do it, why did you bother to ask?

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    17
    Quote Originally Posted by CommonTater View Post
    Yep, you can do that too...
    But if you already knew how you wanted to do it, why did you bother to ask?
    I new what i wanted to do but just needed to find out how to separate the numbers.

    Thanks for all the help.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Teardrop3903 View Post
    I new what i wanted to do but just needed to find out how to separate the numbers.

    Thanks for all the help.
    Ahhh ... Next time, try looking in your C Library documentation first.
    Knowing where and how to look stuff up when you need it is a very valuable skill for a programmer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. File IO with .Net SDK and platform SDK
    By AtomRiot in forum Windows Programming
    Replies: 5
    Last Post: 12-14-2004, 10:18 AM