String Help

This is a discussion on String Help within the C Programming forums, part of the General Programming Boards category; Hey guys i have been trying to code something with strcmp and it didnt work out Code: #include <stdio.h> #include ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    183

    String Help

    Hey guys i have been trying to code something with strcmp and it didnt work out
    Code:
    #include <stdio.h>
    #include <string.h>
    int main(void)
    { 
    	int age;
    	char name[41];
    	fputs("Please Enter your age : ",stdout);
    	scanf("%d",&age);
    	printf("Please Enter your name: ");
    	scanf("%s",name);
    
    	
    	if(strcmp(name,"Bruce")&& (age<13||age>19))
    		puts("Your the choosen one ");
    	else
    	puts("Your not specail");
    	return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by lolguy View Post
    Hey guys i have been trying to code something with strcmp and it didnt work out
    I'm sorry to hear that.



    In addition, strcmp does not return true/false, as it is impossible to denote the three possibilities (less than, equal to, greater than) in a true/false idiom. So don't check for true/false.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    This:
    Code:
    if(strcmp(name,"Bruce")&& (age<13||age>19))
    		puts("Your the choosen one ");
    	else
    	puts("Your not special");
    should be this:
    Code:
    if(strcmp(name,"Bruce")&& (age<13||age>19))
    		puts("You're the chosen one ");
    	else
    	puts("You're not special");
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Hey, Diny, did you forget to change the copied statement to say == 0 after strcmp(), by any chance - as I can't for my life see what the difference is between the corrected and first version is.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    LOL. That's because I used American English and not the Queen's English.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by Dino View Post
    This:
    Code:
    if(strcmp(name,"Bruce")&& (age<13||age>19))
    		puts("Your the choosen one ");
    	else
    	puts("Your not special");
    should be this:
    Code:
    if(strcmp(name,"Bruce")&& (age<13||age>19))
    		puts("You're the chosen one ");
    	else
    	puts("You're not special");
    aha! purely a matter of linguistics
    ROTFLOL

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Dino View Post
    LOL. That's because I used American English and not the Queen's English.
    Ah, ok - so you only corrected the meaningless bits... ;-)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by itCbitC View Post
    ROTFLOL
    Is that one of those secret codes you need a calculator for?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by MK27 View Post
    Is that one of those secret codes you need a calculator for?
    Not really but googling the acronym might help.
    http://en.wiktionary.org/wiki/ROTFLOL
    that's because for the longest time I couldn't figure out what changes Dino made until it finally dawned on me and I couldn't help feeling totally asinine and hence the expression.
    Last edited by itCbitC; 12-10-2008 at 02:32 PM.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    213
    Quote Originally Posted by MK27 View Post
    Is that one of those secret codes you need a calculator for?
    Rolls On The Floor Laughing Out Loud

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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