Thread: valid coding

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    valid coding

    is this valid.. i mean.. it doesnt really work.. but can i code something like this

    Code:
    struct modes {
           char *sbuf;
    };
    
    int main( int argc, char *argv[] )
    {
    
    struct modes m;
    char buf[256];
    char ch;
    
     if( argc != 3 )
     {
       fprintf( stderr, "--Usage: %s <file> <mode>", argv[1] );
       exit( 1 );
     }
    
     m.sbuf = (char *)&argv[2] ;
     printf( "%s", m.sbuf );
     getchar( );
     return 0;
    
    }
    just curious, tring to find all sours of ways to code just a simple program
    Only the strong survives.

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    I've never messed around with that before, but I don't think you could use valid pointers to argv. Maybe I'm wrong. Simply copying arv[] would work, of course.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    how can i use the switch statment for char's
    Only the strong survives.

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    could you be more specific?

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    nm lame questions sorry.. thanx =) im just tring new things out.. for better coding
    Only the strong survives.

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    > how can i use the switch statment for char's

    You can do that like this:

    Code:
    char ch;
    switch (ch)
    {
        case 'a': ...
        ...
    }

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    Ya i know.. i got that part working.. i was just getting an error before.. but i realized what i was doing wrong =) thanx anyways
    Only the strong survives.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > m.sbuf = (char *)&argv[2] ;

    Why not?
    m.sbuf = argv[2] ;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  2. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  3. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM