function that modifies a string

This is a discussion on function that modifies a string within the C Programming forums, part of the General Programming Boards category; i have to write a small funtion that modifes a string by replacing every occurence of the letters foo by ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    Question function that modifies a string

    i have to write a small funtion that modifes a string by replacing every occurence of the letters foo by aaa. an example of the string is "food fool" and should become "aaad aaal". i've written this function and i just want to know if i got it right because i'm not that good when it comes to functions. thanks
    Code:
    void censor(char s[])
    { 
       int i; 
       for(i=0; s[i]!='\0'; i++)
          if (s[i]=='f' && s[i+1]=='o' && s[i+2]=='o')
          s[i]=s[i+1]=s[i+2]='a';
       return a; 
    }

  2. #2
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    >i just want to know if i got it right
    Does it work? If it works with any test cases you come up with, you got it right.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21