4 Replies - 1461 Views - Last Post: 01 April 2011 - 09:46 AM Rate Topic: -----

#1 wasenmel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 29-March 11

char ch =* const char ch2; how?

Posted 01 April 2011 - 09:25 AM

how do i assign a constant pointer character value to a non constant char?
what i am trying to do is make a temporary character to work on with the same
characters of the constant char given by value??
this is my error:
1>c:\users\nono\documents\visual studio 2005\projects\20090176010_ass4\20090176010_ass4\arroperations.cpp(6) : error C2440: 'initializing' : cannot convert from 'const char *' to 'char'



int ArrOperations::getSize(const char* ch)
{   int c=0;
     char ch1=ch;//error 
	// if(this -> getSize(ch1)!=strlen(ch1))
     if(this!=NULL)
	 {   c++;
		 getSize();
	 }
		 
	 return c;
}



Is This A Good Question/Topic? 0
  • +

Replies To: char ch =* const char ch2; how?

#2 wasenmel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 29-March 11

Re: char ch =* const char ch2; how?

Posted 01 April 2011 - 09:31 AM

c++ not java
Was This Post Helpful? 0
  • +
  • -

#3 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: char ch =* const char ch2; how?

Posted 01 April 2011 - 09:36 AM

This belongs in the C/C++ Forum, not Java.

You are saying char, but you are writing char*. Obviously you are dealing with a char array (cstring), not a char. Since you are only trying to determine the size of the string, why are you trying to assign it to a new pointer? Just use the one that is passed into the function and loop through the array until you find the '\0' null char terminator.
Was This Post Helpful? 0
  • +
  • -

#4 wasenmel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 29-March 11

Re: char ch =* const char ch2; how?

Posted 01 April 2011 - 09:39 AM

Ok thanks ...but i'm using recursion not loop ..(teacher rules)!
Was This Post Helpful? 0
  • +
  • -

#5 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: char ch =* const char ch2; how?

Posted 01 April 2011 - 09:46 AM

Then on the recursive call send ch+1 to the function.

And by the way, why are you not using the return value of the function? How are you going to count up to the full length without using the lengths returned by the recursive calls to the function?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1