回 帖 发 新 帖 刷新版面

主题:关于文本(textbuffer)的C语言实现问题

#ifndef TEXTBUFFER_H
#define TEXTBUFFER_H

typedef struct textbuffer *TB;

/* Allocate a new textbuffer whose contents is initialised with the text given
 * in the array.
 */

TB newTB (char text[]);

/* Free the memory occupied by the given textbuffer.  It is an error to access
 * the buffer afterwards.
 */
void releaseTB (TB tb);

/* Allocate and return an array containing the text in the given textbuffer.
 */
char *dumpTB (TB tb);

/* Return the number of lines of the given textbuffer.
 */
int linesTB (TB tb);

/* Swap the two given lines in the textbuffer.
 *
 * - The program is to abort() with an error message if line 'pos1' or line
 *   'pos2' is out of range.  The first line of a textbuffer is at position 0.
 */
void swapTB (TB tb, int pos1, int pos2);

/* Merge 'tb2' into 'tb1' at line 'pos'.
 * 
 * - Afterwards line 0 of 'tb2' will be line 'pos' of 'tb1'.
 * - The old line 'pos' of 'tb1' will follow after the last line of 'tb2'.
 * - After this operation 'tb2' can not be used anymore (as if we had used
 *   releaseTB() on it).
 * - The program is to abort() with an error message if 'pos' is out of range.
 */
void mergeTB (TB tb1, int pos, TB tb2);

/* Copy 'tb2' into 'tb1' at line 'pos'.
 * 
 * - Afterwards line 0 of 'tb2' will be line 'pos' of 'tb1'.
 * - The old line 'pos' of 'tb1' will follow after the last line of 'tb2'.
 * - After this operation 'tb2' is unmodified and remains usable independent
 *   of 'tb1'. 
 * - The program is to abort() with an error message if 'pos' is out of range.
 */
void pasteTB (TB tb1, int pos, TB tb2);

/* Cut the lines between and including 'from' and 'to' out of the textbuffer
 * 'tb'.
 *
 * - The result is a new textbuffer (much as one created with newTB()).
 * - The cut lines will be deleted from 'tb'.
 * - The program is to abort() with an error message if 'from' or 'to' is out
 *   of range. 
 */
TB cutTB (TB tb, int from, int to);

/* Copy the lines between and including 'from' and 'to' of the textbuffer
 * 'tb'.
 *
 * - The result is a new textbuffer (much as one created with newTB()).
 * - The textbuffer 'tb' will remain unmodified.
 * - The program is to abort() with an error message if 'from' or 'to' is out
 *   of range. 
 */
TB copyTB (TB tb, int from, int to);

/* Remove the lines between and including 'from' and 'to' from the textbuffer
 * 'tb'.
 *
 * - The program is to abort() with an error message if 'from' or 'to' is out
 *   of range. 
 */
void deleteTB (TB tb, int from, int to);


#endif
以上是我摘自国外网站的题目,但是看不太懂。。还请教高手来看看

回复列表 (共14个回复)

11 楼

还是
void releaseTB(TB tb)
{ TB tmp

 while(head != NULL)
 {
  pointer = head;
  head = head->Next;
  free(pointer);
 }




}

12 楼

我自己写了一下,不知道对不对
void releaseTB(tb)
{
   TB pointer;
  
 while(tb!= NULL)
 {
  pointer = tb;
  tb = tb->Next;
  free(pointer);
 }

}

13 楼

memset(p,0,sizeof(p));
memset函数是干什么用?

14 楼

/* Return the number of lines of the given textbuffer.
 */
我感觉这个函数就是数有多少结点并返回吧,我写了写,请指教
int linesTB (TB tb)
{
   int i;
  while(tb!=NULL){
    i++;
   tb=tb->next

}
  return i;

}

我来回复

您尚未登录,请登录后再回复。点此登录或注册