help

This is a discussion on help within the C Programming forums, part of the General Programming Boards category; Hi, I need to do a program that shows the date in this format, 12-jul-2002 from a number input. Im ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    help with typedef struct

    Hi,
    I need to do a program that shows the date in this format, 12-jul-2002 from a number input. Im using this struct:
    Code:
    typedef struct {
    unsigned char day;
    unsigned char month;
    int year;
    } Tdata;
     
    The months are saved in.
    char months[12][4]={"Gen","Feb","Mar","Abr","Mai","Jun","Jul","Ago",
        "Set","Oct","Nov","Des"};
     
    Then I use this function:
    int obtenirData( TData *d, char *text ) {
    */ analizes text and asigns a data to the structure Tdata and retorns -1 if error and 0 if ok. /*
    return 0;
    }
    
     
    Then I use this function:
     
    void donarData( Tdata *d, char *buffer) {
    // writes in buffer a string that contains the data in d
    // Doesnt return anything
    }
    On main I call buffer with:
    gets(buffer);

    My question is how to get the numbers without using scanf and how to put them in the struct Tdata??

    Please help me, Im going crasy....

    Thanx.

    Code Tags added by kermi3
    Last edited by europed; 10-18-2002 at 02:58 PM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >On main I call buffer with:
    >gets(buffer);
    I wouldn't if I were you. Research fgets(), it's has a couple more parameters, but it's much safer.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    I type 12 7 2002. The program finds changes it to jul for me.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    Sorry I got it wrong...
    What I need to do is to store the date in the struct Tdata. The user will introduce the date in this format: 7-jun-1978.

    Code:
    typedef struct {
    	unsigned char dia;
    	unsigned char mes;
    	int 	        any;
    } TData;
    
    
    char mesos[12][4]={"Gen","Feb","Mar","Abr","Mai","Jun","Jul","Ago","Set","Oct","Nov","Des"};
    
    
    void printaMesos(void) {
    
     int i;
     for (i=0;i<12;i++) {
    	puts(mesos[i]);
     }
    }
    
    int obtenirData( TData *d, char *text ) {
    
    /*example obtenirData(&data, "7-Jul-1971");
      analizes text and asigns the data in the fields of the structure     Tdata. Returns -1 if error*/
    
    return 0;
    }
    
    
    void donarData( Tdata *d, char *buffer) {
    // writes to buffer a string that contains the date stored in d
    // Does not return anything
    }
    
    void main() {
    
    
    	 Tdata d;
    	 char buffer[255];
    	 char buffer1[255];
    
    
    	 puts("Type an example string (7-Jul-1971)");
    	 gets(buffer1);
    
    	 if (obtenirData(&d, buffer1)==0) {
    			donarData(&d,buffer);
    			puts(buffer);   
    	 } else {
    
    		 puts("error in format");
    
    	 }
    
    	 printaMesos();
    
    }
    Thanx again!!

Popular pages Recent additions subscribe to a feed

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