Thread: Reserve the character in a string

  1. #1
    Registered User alice's Avatar
    Join Date
    Mar 2004
    Posts
    36

    Unhappy Reserve the character in a string

    How can I use ADT to complete a function takes in a string
    parameter (char array) that contains one or more sentences;
    each sentence is terminated by the full-stop ('.') or the
    NULL character. When the function returns, the characters in
    each of the functions are reversed in order, and also all
    numeric digit characters are discarded. The function should
    also return the number of sentences in str as the return
    value.

    ie, if str is "ABC D2EF. GHI3J. KLM", then after calling the function str
    becomes "FED CBA. JIHG. MLK". The function should also return 3, indicating that there
    are 3 sentences.


    Code:
    #include <stdio.h>
    
    #define STACKSIZE 1024
    
    char stack[STACKSIZE];
    int stackptr = 0;
    
    void push(char ch) {    /* pushes the character ch onto the stack */
      if (stackptr == STACKSIZE)
        return;
      stack[stackptr++] = ch;
    }
    
    char pop() {        /* pops and returns the top character */
      if (stackptr == 0)
        return '\0';
      return stack[--stackptr];
    }
    
    int isEmpty() {    /* return 1 if the stack is empty, 0 otherwise */
      return (stackptr == 0);
    }
    
    int reverseSentence(char str[]) {
     
    }


  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >contains one or more sentences;
    >each sentence is terminated by the full-stop ('.') or the NULL character.
    If you can have multiple sentences each possibly null terminated, how do you know when the string ends without also passing size information?
    My best code is written with the delete key.

  3. #3
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    Quote Originally Posted by Prelude
    >contains one or more sentences;
    >each sentence is terminated by the full-stop ('.') or the NULL character.
    If you can have multiple sentences each possibly null terminated, how do you know when the string ends without also passing size information?
    If she reads in characters from a stream till she gets an EOF. I don't see any problem whatsoever.
    [added later]
    My bad, the function has to take in a string.
    Last edited by pinko_liberal; 06-13-2004 at 08:59 AM.
    The one who says it cannot be done should never interrupt the one who is doing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM