* quick question *

This is a discussion on * quick question * within the C Programming forums, part of the General Programming Boards category; mmmm....I have a real quick question I hope someone can answer within an hour and a half....heh....here's the thing...... We ...

  1. #1
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77

    * quick question *

    mmmm....I have a real quick question I hope someone can answer within an hour and a half....heh....here's the thing......

    We need to create a way to put our code into "silent mode"....if the user passes a "q" to the program through the command line, then none of the printf's need to be shown....only the scanf's......it's supposed to show nothing except when they choose to "PRINT" the records.....so I figured the easy way to do it would be like this:

    Code:
    int silent=0;
    
    if (silent=1)
    {
        printf("a bunch of junk");
    }
    
        scanf("%c",&character);
    something of the nature....put a check to see if it has been flagged as silent...problem is I can't get my char *argv working...at the very beginning of the program i'm trying something like:

    Code:
    if (char *argv[1]=='q')
    {
         silent = 1;
    }
    but that's not setting it equal to one...or something isn't going right....can someone tell me how to make this successfully set to 1 if the user passes a 'q'? thanks.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Location
    computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
    Posts
    61
    if (char *argv[1]=='q')
    the above line is comparing 'q' to an address. Remember the char *argv[] is an array is char pointers.

    Try this:
    if(argv[1][0] == 'q')

  3. #3
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    that code works fine when i pass a q.....but if i don't pass anything the code flips out and shut down....suggestions??

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    that code works fine when i pass a q.....but if i don't pass anything the code flips out and shut down....suggestions??

    if (char *argv[1]=='q')
    1) How about you check argc before using argv?
    2) Why the hell do you have 'char*' in there??

    if( argc > 1 && *argv[1] == 'q' )

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

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