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

string question

This topic is 5012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

void mystery1( char *, const char * );

int main()
	char string1[ 50 ], string2[ 50];

	cout << "Enter two strings: ";
	cin >> string1 >> string2;
	mystery1( string1, string2 );
	cout << string1 << endl;

	return 0;

void mystery1( char *s1, const char *s2 )
	while ( *s1 != '\0' )

	for ( ; *s1 = *s2; s1++, s2++ )
when i type in two strings, lets say for example quake, con what happens when ++s1 is reached? [edited by - TheOne1 on March 26, 2004 1:40:18 AM]

Share this post

Link to post
Share on other sites
Not if there''s still space in the buffer. It''s skipping ahead to the null-terminator of the ''string'' at s1, which might (hee hee) be shorter than the 50 chars that are allocated there in main. In which case it will happily continue along with the for loop, with the net effect of... yeah, compile it yourself and find out.

Share this post

Link to post
Share on other sites