Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (christos):

C++, C-Strings ! That's my problem: http://screencast.com/t/sBjt9Dzoq7RZ That's my code: http://pastebin.com/TLXgMRJk It asks for me to copy one string to another without using predefined functions apart from gets(). as strcpy() is a predefined function , I can't use this to solve my problem. Is there another way to copy one string to another ? Please help me. Thanks a lot for reading .

OpenStudy (christos):

My updated code: http://pastebin.com/ZC8dzLJQ

OpenStudy (christos):

http://pastebin.com/pzF5bDmP

OpenStudy (callisto):

May I know what your codes do?

OpenStudy (christos):

All of my codes are attempts to solve this problem: http://screencast.com/t/sBjt9Dzoq7RZ This here is my latest code: http://pastebin.com/pzF5bDmP I still can't do it though

OpenStudy (callisto):

s1 and s2 are of string type?

OpenStudy (christos):

they are strings yes

OpenStudy (christos):

char type

OpenStudy (callisto):

char type? Why?

OpenStudy (christos):

The int type was giving me some extra errors. Plus why not char type ?

OpenStudy (callisto):

string s1 ^Type string

OpenStudy (christos):

Now the errors got more

OpenStudy (christos):

For example I can't use gets() now

OpenStudy (christos):

Updated code: http://pastebin.com/qdvc8wJr I am getting close

OpenStudy (e.mccormick):

Well, their instructions contradict themselves.... if you were not able to use predefined functions how could you print? Hehe. But I think they mean for the copy. I'm looking at the code now.

OpenStudy (christos):

yea most likely ;p

OpenStudy (e.mccormick):

AH! Your loop! ``` for (i=0; S1[i]!='\0';i++){ } ``` Nothing in that.

OpenStudy (christos):

http://pastebin.com/12Sm5EhT 99% completed :D

OpenStudy (christos):

In this loop I just want i++ so that I can say var = i

OpenStudy (christos):

after the loop is over

OpenStudy (e.mccormick):

OK. So you are using it to find the last position. I would normally copy inside the loop that way.

OpenStudy (christos):

Ok it's done. So that was the solution! http://pastebin.com/VietWxAf

OpenStudy (christos):

Took the life out of me :p

OpenStudy (e.mccormick):

Hehe. The fun thing is, you could do it all in one loop. Copy and cout one right after the other, stopping when you hit the null.

OpenStudy (christos):

can you show me ??

OpenStudy (e.mccormick):

I'll have to do it later. Need to head to work pretty soon.

OpenStudy (christos):

ok man its np

OpenStudy (e.mccormick):

It can be really good to see more than one way to do things. That is why I have shared some alternate solutions after you were done with your other projects.

OpenStudy (christos):

Yea they are interesting too

OpenStudy (e.mccormick):

http://pastebin.com/bQEG9zDa

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!