![]() |
| |||||||
| C++ Forum C++ Forum. C++ Programming |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
| |||
| C programming arrays?
Hi guys, I'm writing a function that will replace the last occurrence of a character in a string. Although, it seems to replace all the characters in the string. This is what i have so far: char s[] = hello123 old = l new = b void replace_last(char s[], int old, int new) { size_t i; size_t index = 0; while(s[index] == old){ index++; } for(i=0; s[i] != '{rss:Content}'; i++){ if(s[i+index] == old){ s[i+index] = new; } } } So i'm trying to get the output of 'helbo123' but instead I get 'hebbo123'. Anyone care to elaborate on this? Any help would be appreciated. hmm sorry, i should have added that i'm trying to do it without any standard library functions. Thanks (other than stdio.h) actually, I just figured out a way without using strlen from That Guy's example. Thanks |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help with combining two PHP arrays please? | chilleo | PHP Forum | 0 | 08-30-2008 12:57 AM |
| PHP palindrome using arrays? how? | jojo | PHP Forum | 0 | 06-05-2008 12:33 AM |
| Arrays in Perl? | Etienne 4u | Perl Forum | 1 | 05-18-2008 09:04 PM |
| getting multiple arrays | Colin Harris | PHP Forum | 6 | 02-15-2004 06:23 AM |
| Creating arrays | paulm844 | PHP Forum | 2 | 09-16-2003 07:51 AM |