Thread: String Help

  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,336
    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
    Chappell Hill, Texas
    Posts
    2,332
    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");
    Mainframe assembler programmer by trade. C coder when I can.

  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
    Chappell Hill, Texas
    Posts
    2,332
    LOL. That's because I used American English and not the Queen's English.
    Mainframe assembler programmer by trade. C coder when I can.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    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,059
    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 03:32 PM.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    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, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM