Thread: strcmp problem

  1. #1
    Registered User
    Join Date
    Apr 2008

    strcmp problem

    hi guys, im trying to do some comparison but the compiler keeps telling me i cant make pointers from integer. can anyone tell me what i did wrong please? thanks.

    char* line;
    line = readline("enter somethin");
    if(strcmp(line[strlen(line)], "b") == 0 ) { 

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    is a char - which the compiler interprets as an integer, since it's definitely not a pointer. Also, it is guaranteed to be not equal to "b", since it's the last character of the string, which as long as strlen() itself is not broken, always zero.

    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.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    Strings are always arrays (which can only be passed as pointers to another function[1]), because even an empty string is 1 byte and even a string with one character such as "a" is 2 bytes. That's why it expects a pointer to your string, and not a char.

    [1] Intrigued? Read more here:
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Apr 2008
    great thanks. i figure i would just do a normal comparison instead of using strcmp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. help with strcmp
    By blork_98 in forum C Programming
    Replies: 8
    Last Post: 02-21-2006, 08:23 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM