Linux_C筆記day07

#realloc函數
定義:
    在原有的堆空間上進行擴充或者縮小;
    The realloc() function changes the size of the memory block pointed to by ptr to size bytes.  The contents will be  unchanged  in  the  range from  the  start  of  the  region up to the minimum of the old and new sizes.  If the new size is larger than the old size, the added  memory will  not be initialized.  If ptr is NULL, then the call is equivalent to malloc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr).  Unless ptr is NULL, it must have been returned by an earlier  call  to  malloc(), calloc()  or realloc().  If the area pointed to was moved, a free(ptr) is done.

函數原型:
    void *realloc(void *ptr, size_t size);
#getline函數
定義:
    getline調用了malloc函數最後需要釋放其接受的指針;lineptr:指向存放該行的指針,n:如果是系統指針,請填0;stream:文件描述符。函數返回值,成功:返回讀取的字節數,失敗:返回-1;
    getline() reads an entire line from stream, storing the address of the buffer containing the text into *lineptr.  The buffer  is  null-termi‐ nated and includes the newline character, if one was found.

       If *lineptr is NULL, then getline() will allocate a buffer for storing the line, which should be freed by the user program.  (In  this  case,
the value in *n is ignored.)

       Alternatively,  before  calling  getline(),  *lineptr  can  contain  a pointer to a malloc(3)-allocated buffer *n bytes in size.  If the buf‐
 fer  is  not  large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary.

       In either case, on a successful call, *lineptr and *n will be  updated to reflect the buffer address and allocated size respectively.
函數原型:
     ssize_t getline(char **lineptr, size_t *n, FILE *stream);
樣列:
       #define _GNU_SOURCE
       #include <stdio.h>
       #include <stdlib.h>

       int
       main(void)
       {
           FILE *fp;
           char *line = NULL;
           size_t len = 0;
           ssize_t read;

           fp = fopen("/etc/motd", "r");
           if (fp == NULL)
               exit(EXIT_FAILURE);

           while ((read = getline(&line, &len, fp)) != -1) {
               printf("Retrieved line of length %zu :\n", read);
               printf("%s", line);
           }

           free(line);
           exit(EXIT_SUCCESS);
       }


#strtok函數
定義:
    切割字符串函數,改變原本的字符串,將str字符串按delim字符串中有的字符進行切割,返回切割後的字串首地址,原str字串爲切割過後的首地址。
    
函數原型:
    char *strtok(char *str, const char *delim);
樣列:
    void cutchar(char* tmp)
{
       char* p=NULL;
       char* pa=NULL;
       p = strtok(tmp," ");
       while(p!=NULL){
              pa=p;
              p=strtok(NULL," ");    //切割後的首地值的宏爲NULL
        }
        tmp = pa;
 }

#framebuffer(幀緩衝)
幀的最低數量爲24(人肉眼可見)
顯卡與幀的關係
由cpu調節其數據傳輸速率來輸出其三基色的配比
三基色RGB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章