Thread: Auto generated

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    9

    Auto generated

    How to make the index number auto generated by the program itself??

    AND how to make the index number unique(no duplication of the same number??

    i want to know the way to make the program to generate index number in order manner(not random)

    example:
    ID no.1001

    ID no.1002

    ID no.1003 and so on


    please tell me with example
    Last edited by Daniel decosta; 09-28-2002 at 01:18 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >does anybody know what is the command to make the program to generate index no. by itself??
    >How to make the index number auto generated by the program itself??
    You asked the same question twice but with different wording. The first step is to determine what kind of index numbers you need, then you can develop an appropriate algorithm to generate them. Otherwise you're just stuck with random numbers:
    Code:
    int index = rand();
    >please tell me with example
    You need to ask a better question if you want a good answer. Being vague is bad when programming. Also, unless the example is simple you shouldn't expect someone else to write it for you, this is considered rude. Your problem is just that, your problem. We are happy and willing to help, but we won't do it all.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788

    Re: Auto generated

    Originally posted by Daniel decosta
    does anybody know what is the command to make the program to generate index no. by itself??
    How to make the index number auto generated by the program itself??

    AND how to make the index number unique(no duplication of the same number??

    please tell me with example
    If you wanna know how to generate random numbers, then search the board for threads on random numbers.

    Otherwise, I don't know what you want.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    9
    i want to know the way to make the program to generate index number in order manner(not random)

    example:
    ID no.1001

    ID no.1002

    ID no.1003 and so on

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Daniel decosta
    i want to know the way to make the program to generate index number in order manner(not random)

    example:
    ID no.1001

    ID no.1002

    ID no.1003 and so on
    I still don't understand your question... but is the answer this:

    Set an int variable to 1001, then increment it by one whenever you want. Like
    Code:
    int i;
    i = 1001;
    i++;
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    9
    i means the index number generated(accordingly) must unique.
    there suppose to be no duplication of the same index number.
    Example:

    ID no. 1001
    Name:Amy
    Age:20

    ID no. 1002
    Name:Danny
    Age: 18

    ID no. 1003
    Name:Tommy
    Age:25

    and there cannot have two same index number.Like this
    ID no. 1001
    Name:Amy
    Age:20

    ID no. 1002
    Name:Danny
    Age: 18

    ID no. 1001
    Name:Tommy
    Age:25
    after that
    all these info will be save into a file.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Try this:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char buf[BUFSIZ];
        int i;
        
        for (i = 0; i < 10; i++)
        {
            sprintf (buf, "name %d", i);
            puts(buf);
        }
        
        return 0;
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    KingoftheWorld
    Guest
    Addition to Hammer code, you need to define BUFSIZ.

    #define BUFSIZE 10

    KingoftheWorld
    KingoftheWorld
    __________________________________________________
    Love Relationship is like a Software Life Cycle development.
    It needs to be tried to understand carefully at the early phase and Keep up with enhancing and solid maitainence at the last phase!
    _________________________________________________

  9. #9
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by KingoftheWorld
    Addition to Hammer code, you need to define BUFSIZ.

    #define BUFSIZE 10

    have you ever programmed in C before? well, if you have, then next time you do take a look at stdio.h in your include directory. you might be suprised.
    hello, internet!

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    9
    ___________________
    #include <stdlib.h>
    int main (void) {
    for ( ;; )
    malloc (10000);
    return 0; }
    ______________
    what does the about statement do???

  11. #11
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Daniel decosta
    ___________________
    #include <stdlib.h>
    int main (void) {
    for ( ;; )
    malloc (10000);
    return 0; }
    ______________
    what does the about statement do???
    just informing you, my sig IS joke code just in case you thought it did anything useful.

    "the about statement" - which statement are you referring to?
    hello, internet!

  12. #12
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Actually you could save one line in your sig by dropping the return 0; statement.

    The compiler automatically adds it if it's omitted (this is in the standard).
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Are auto pointers any good?
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2007, 11:07 AM
  3. [VS 2005] Auto generated skeleton code
    By cboard_member in forum Tech Board
    Replies: 4
    Last Post: 03-06-2006, 12:45 PM
  4. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  5. auto <cringe> generated <cringe> code <cringe>
    By RobS in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-22-2001, 04:46 AM