Comparing stringish

This is a discussion on Comparing stringish within the C Programming forums, part of the General Programming Boards category; okay so another problem now i have in a new program is the following Code: if (strcmp ("C_CONVERT",argv[1] == 0)) ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    27

    Comparing stringish

    okay so another problem now i have in a new program is the following

    Code:
    if (strcmp ("C_CONVERT",argv[1] == 0))
            {
                printf ("C_CONVERT\tConverts one file type to another\n");
                printf ("C_CONVERT\t[source file name] [destination file name]\n");
                printf ("\nTo change the file type specify a source file with\nextension and then the desired file name with new\nextension/n/n");
            
            }
            else if (strcmp ("C_COPY",argv[1]== 0))
            {
                printf ("C_COPY\tCopies one file to another location\n");
                printf ("C_COPY\t[source file] [destination file]\n");
                printf ("\nTo copy a file specify a source file and\nthen the desired file name/n/n");
            
                }
            else if (strcmp ("C_DELETE",argv[1] == 0))
            {
                printf ("C_DELETE\tDeletes one file at a time\n");
                printf ("C_DELETE\t[file name] \n");
                printf ("\nTo delete a file just specify a file name/n/n");
            
                }
            else if (strcmp ("C_FIND",argv[1] == 0))
                {
                printf ("C_FIND\tSearches for a text string in a file\n");
                printf ("C_FIND\t[file name] [string]\n");
                printf ("\nTo find a string in a file specify the\nfile and then the string needed to find/n/n");
                
                }
            else if (strcmp ("C_HELP",argv[1] == 0))
                {
                printf ("C_HELP\tProvides help information for my C commands\n");
                printf ("C_HELP\t[command]\n");
                printf ("\n\t\tcommand - displays information on that command/n/n");
                
                }
            else if (strcmp ("C_MORE",argv[1] == 0))
                {
                printf ("C_MORE\tDisplays output 10 lines at a time\n");
                printf ("C_MORE [file name]\n");
                printf ("\nTo view a file 10 lines at a time specify file name and at every page break press any key to continue/n/n");
                
                }
            else
            {
                printf("This command is not supported be the c_help utility");
                
                
            }
    i'm tring to get what a user types into the dos prompt bit and compare it to i preset in an if statement but the only problem i have is that it compiles and builds successfully with only 12 warnings so then i go and run it and in dos and i get the send a report to microsoft page which then ends the program

    how can i sort out the warnings which don't seem to make sense and can i put in a toupper check in there to help the user in what they type in



    ps YES i know it looks very familier to the help command from dos
    Always posting problems

    Always needing help

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,260
    All your if statements are wrong. They should look more like:
    Code:
    if (strcmp ("C_CONVERT",argv[1]) == 0)
    Notice the change in parenthesis.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>with only 12 warnings
    My super-sight binoculars don't go as far as letting me see the warnings on your screen from my desk here; best post the warnings on the forum to make things easier.

    >> can i put in a toupper check..
    Sure. An good way would be to make your own function that does the same as strcmp(), but is case insensitive.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    27
    Quote Originally Posted by bithub
    All your if statements are wrong. They should look more like:
    Code:
    if (strcmp ("C_CONVERT",argv[1]) == 0)
    Notice the change in parenthesis.

    now im feelling rather sh!ty as i did not see that


    but can i add in a to upper bit or shall i just rewrite that but with lower case

    EDIT: just saw the above post and i thought about a function but i think iam going to decide against that because its too complicated for the little assignment im doing
    Last edited by satory; 02-22-2005 at 06:19 PM.
    Always posting problems

    Always needing help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2009, 11:13 AM
  2. bit vs bytes when comparing a file
    By Overworked_PhD in forum C Programming
    Replies: 6
    Last Post: 05-20-2007, 12:22 AM
  3. comparing bitmaps
    By bigSteve in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 10:40 AM
  4. comparing problem
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 03-05-2002, 06:19 AM
  5. comparing struct members
    By breed in forum C Programming
    Replies: 4
    Last Post: 11-22-2001, 12:27 PM

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