Thread: type casting error

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    19

    type casting error

    i just want to calculate the length of char*,so i write
    Code:
    int len(char* str)
    {
    	int i = 0;
    	while (*str != "/0")
    	{
             ++i;
    		 ++str;
    	}
    	return i;
    }
    but the error “there is no cast from const char * to int”?
    how to deal with it?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    By realising that "/0" is not the same thing as '\0'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    19
    ok , that's the thing ,i correct it ,thank you !

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I always keep wondering if the people who mix up '\0' with "/0" are linux people.
    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.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    That mistake is way too common. For the same reason you assume linux users get confused about this, I could blame people on the internet in general. The internet uses the same directory marker as linux does.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    True, true. I was just sort of wondering if people mistook it for being "/0" because it's the "typical" path separator (non-Windows users don't see "\" very often, heh).
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advantages of c++ type casting over c type casting
    By kaibalya2008 in forum C++ Programming
    Replies: 10
    Last Post: 05-05-2009, 11:09 AM
  2. Replies: 3
    Last Post: 02-18-2008, 10:52 AM
  3. difference between type conversion and type casting
    By Bargi in forum C Programming
    Replies: 1
    Last Post: 01-23-2007, 03:17 AM
  4. Type Casting?
    By Megatron in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2002, 01:07 PM
  5. type casting
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 10-17-2001, 01:25 PM

Tags for this Thread