View Single Post
Old 07-12-2003, 11:15 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Re: Reversing String logic

this code does nothing. why is it there?

Quote:
Originally posted by M3GAPL3X
Code:
	while (strng[i]) //while string isn't a null character '\0'
	i++; //increment i and store in string

	strng[i] = '\0';
the inner loop shouldn't be there. think about how the characters will be copied. strng[0] -> reverse[n - 1], strng[1] -> reverse[n - 2] and so on. you only need one loop for this.
also, remember to put the '\0' at the end of 'reverse'.

Quote:
Code:
	n = strlen(strng); //find the length of the string after
	

	for (i=0; i < n; i++)
		for (j = n; j >= 0; j--)
		reverse[i] = strng[j];
		//i--;
joe_bruin is offline   Reply With Quote