Archived

This topic is now archived and is closed to further replies.

tonymontana

again a QUESTÝON about pointers

Recommended Posts

tonymontana    100

#include <iostream>
using namespace std;


/////////////////////////////////////PROTOTYPES/////////////////////////////////////////////

unsigned int mystrlen(char*);
char* mystrcpy(char* , char* const); 

/////////////////////////////////////MAÝN///////////////////////////////////////////////////


int main()
{
	char yazi2;
	char* yazim="bu alemin krali geliyorrrr";
	cout<<mystrlen(yazim);
	mystrcpy(yazi2,yazim);
	cout<<yazim;
	return 0;
}

//////////////////////////////////////DEKLERATÝON//////////////////////////////////////

unsigned int mystrlen(char* anystr)
{
	unsigned int cntr1=0;
	for(  ; *(anystr+cntr1)!=''\0''; ++cntr1)
	{
	}
	return cntr1;
}
char* mystrcpy(char* destination,char* const  source)
{
	unsigned int cntrdes=mystrlen(destination);
	unsigned int cntrsour=mystrlen(source);
	switch (cntrdes>=cntrsour)
	{
	case true:
		{
			int cntr1=0;
			for(;cntr1<=cntrsour;++cntr1)
			{
				*(cntrdes+cntr1)=*(source+cntr1);  // this is causing error

			}
		*(destination+cntr1)=''\0'';   // this too..	             

		}
	case false:
		{
			int cntr2=0;
			for( ; cntr2<=cntrdes;++ cntr2)
			{
				*(destination+cntr2)=*(source+cntr2);  // this is also causing error

			}
			*(destination+cntr)=''\0'';   // this too..

		}
	}
	
	return destination;
}

/*  all i want to do is   with this code is to assign value of source char to  destination char
 as that
     
	   destination[cntr1]=source[cntr1];     // but i want to do that wiht pointers

       what is wrong at that code and how can i do that
	   *(cntrdes+cntr1)=*(source+cntr1);       ???

  second question is
  how can i get the content of a pointer to char*(assume as a array..)

  for(cntr2=0;true;++cntr2)
  {
  *(destination+cntr2);
  }

*/


the archer who shoots his arrow beyond his target is no more successful than the one who''s arrow didn''t even reach the target.

Share this post


Link to post
Share on other sites
Codman    181
I would recomend the following changes:

main():

"char *yazi2" instead "char yazi2"

You receive an error in true statement in line *(cntrdes + cntr1) =... because instead of cntrdes should be destination . Cntrdes is an int and is a right-value.

Last error: cntr should be replaced with cntr2.

Good luck!

-----------------------------
Codman - "The source for all things"
"We design for eternity"

Mail: Codman_Wu@personal.ro

Share this post


Link to post
Share on other sites