Computer Forum  

Go Back   Computer Forum > Computer Forums > Programming Forum > C++ Forum

C++ Forum C++ Forum. C++ Programming


C programming arrays?

C++ Forum

C++ Forum. C++ Programming


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-12-2008, 01:27 PM
Junior Member
 
Join Date: Jan 2008
Posts: 7
matt d RSS Feed
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT. The time now is 04:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93