Help me figure this question

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 28
Reputation: Sh13 is an unknown quantity at this point 
Solved Threads: 0
Sh13 Sh13 is offline Offline
Light Poster

Help me figure this question

 
0
  #1
Mar 26th, 2008
Q. Write a function Stars() whose input are an array of characters(a), the size of the array(n), and a character(ch). This function should replace all occurrences of ch in the array, a, with a star(*), and return the number of times the replacement was made.

So far I have the function prototype
  1. int stars(char a[n], char ch, int n)
  2. {
  3. }
Last edited by Narue; Mar 26th, 2008 at 9:25 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,787
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help me figure this question

 
0
  #2
Mar 26th, 2008
In other words, you have nothing. Give it a try first, then we'll be more inclined to help you.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 28
Reputation: Sh13 is an unknown quantity at this point 
Solved Threads: 0
Sh13 Sh13 is offline Offline
Light Poster

Re: Help me figure this question

 
0
  #3
Mar 26th, 2008
does this look ok?
  1. int stars(char a[n], char ch, int n)
  2. {
  3. int replacenum = 0;
  4. int i;
  5.  
  6. for ( i = 0; i < replacenum; i++)
  7. {
  8. if (a[i] == ch)
  9. {
  10. a[i] = '*';
  11. }
  12. }
  13. replacenum = a[n];
  14.  
  15. return replacenum;
  16. }
Last edited by Narue; Mar 26th, 2008 at 12:32 pm. Reason: Added code tags and formatted the code. Do it yourself next time.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,787
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help me figure this question

 
0
  #4
Mar 26th, 2008
>does this look ok?
No, it doesn't. Did you compile and run it before asking that?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 28
Reputation: Sh13 is an unknown quantity at this point 
Solved Threads: 0
Sh13 Sh13 is offline Offline
Light Poster

Re: Help me figure this question

 
0
  #5
Mar 26th, 2008
I did now and it doesn't work. I'll figure it out.
Last edited by Sh13; Mar 26th, 2008 at 1:09 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC