1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Putting Auto Numbers in a File

Discussion in 'C#' started by shah123, Apr 5, 2007.

  1. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    Is there anyway i can put my every entry of username in a file like this e.g. using any auto number generation with every entry

    1. Test
    2. Hello

    After i put them in a file like this i want to search and delete based on the numbers. e.g.

    Please enter the number to delete the data: 1
    "should delete the test from a file"

    Please help. As any suggestions and location of any website will also be helpful.

    Regards,
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    For files you need to be doing the auto generation but for database you can always have the priviledge of using the database field.
     
  3. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Hi Shabbir,

    I dont want database in this situation. I just want to add auto number generation in a file
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    I am not saying you switched to dbs but just saying that you need to be doing it yourself.
     
  5. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Can you give me idea? please
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Read the file and get the last number. Increment it by one and then add one to it and save the next one. Remember when you delete it the record should go but not the numbers but it depends on your implementation requirement.
     
  7. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Hi Shabbir,
    "Read the file and get the last number. Increment it by one and then add one to it and save the next one"

    Can you please tell me in psuedu code or something please small bit implementation?
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    The pseudo looks something like
    Code:
    File f = ReadFile();
    int i = LastNumberInputted(f);
    i++;
    SaveNextRecord(i,Data);
     
  9. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    Code:
    Console.WriteLine("Please Enter your username :");
                        int Counter = 0;
                        s = Console.ReadLine();
                        Counter = Counter + 1;
                        sw.WriteLine(Counter + " " + s);
                        sw.Write(sw.NewLine);
    
    
    1. Where to put while condition so it can read file and increment the counter?
    2. When every time i enter one name it comes out of getusername function and display the menu options again. How to prevent that?

    Regards,
     

Share This Page