Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将*添加到用户定义类型时出现不兼容的指针类型错误 #包括 #包括 #包括 #包括 #包括“textbuffer.h” typedef struct textNode{//基本上包含一行+链接 字符*行; int sLength;//字符串的长度 结构textNode*next; }tNode; 结构文本缓冲区{ int size;//文本缓冲区中的行数 t节点*头; tNode*尾部; } 静态tNode*newTN(char*string,int-sLength,tNode*next); 静态tNode*newTN(char*string,int sLength,tNode*next){ tNode*t=malloc(sizeof(struct textNode)); t->line=malloc(字符大小)*长度); if(字符串!=NULL){ strcpy(t->行,字符串); } t->next=next; 返回t; } 静态无效打印缓冲区(TB){ tNode*curr=tb->head; int i=0; while(curr!=NULL){ 而(curr->line[i]!='\n'){ printf(“%c”,curr->line[i]); i++; } printf(“\n”); i=0; 当前=当前->下一步; } } /*分配一个新的textbuffer,其内容用给定的文本初始化 *在数组中。 */ TB newTB(字符文本[]){ 断言(文本!=NULL); int i=0; 字符c; TB tBuffer=malloc(sizeof(struct textbuffer)); tBuffer->size=0; //tNode*currLine=malloc(sizeof(struct textNode*)); tNode*currLine=newTN(NULL,1,NULL); tNode*currtNode; //currLine->line=malloc(sizeof(char));_C_Debugging - Fatal编程技术网

将*添加到用户定义类型时出现不兼容的指针类型错误 #包括 #包括 #包括 #包括 #包括“textbuffer.h” typedef struct textNode{//基本上包含一行+链接 字符*行; int sLength;//字符串的长度 结构textNode*next; }tNode; 结构文本缓冲区{ int size;//文本缓冲区中的行数 t节点*头; tNode*尾部; } 静态tNode*newTN(char*string,int-sLength,tNode*next); 静态tNode*newTN(char*string,int sLength,tNode*next){ tNode*t=malloc(sizeof(struct textNode)); t->line=malloc(字符大小)*长度); if(字符串!=NULL){ strcpy(t->行,字符串); } t->next=next; 返回t; } 静态无效打印缓冲区(TB){ tNode*curr=tb->head; int i=0; while(curr!=NULL){ 而(curr->line[i]!='\n'){ printf(“%c”,curr->line[i]); i++; } printf(“\n”); i=0; 当前=当前->下一步; } } /*分配一个新的textbuffer,其内容用给定的文本初始化 *在数组中。 */ TB newTB(字符文本[]){ 断言(文本!=NULL); int i=0; 字符c; TB tBuffer=malloc(sizeof(struct textbuffer)); tBuffer->size=0; //tNode*currLine=malloc(sizeof(struct textNode*)); tNode*currLine=newTN(NULL,1,NULL); tNode*currtNode; //currLine->line=malloc(sizeof(char));

将*添加到用户定义类型时出现不兼容的指针类型错误 #包括 #包括 #包括 #包括 #包括“textbuffer.h” typedef struct textNode{//基本上包含一行+链接 字符*行; int sLength;//字符串的长度 结构textNode*next; }tNode; 结构文本缓冲区{ int size;//文本缓冲区中的行数 t节点*头; tNode*尾部; } 静态tNode*newTN(char*string,int-sLength,tNode*next); 静态tNode*newTN(char*string,int sLength,tNode*next){ tNode*t=malloc(sizeof(struct textNode)); t->line=malloc(字符大小)*长度); if(字符串!=NULL){ strcpy(t->行,字符串); } t->next=next; 返回t; } 静态无效打印缓冲区(TB){ tNode*curr=tb->head; int i=0; while(curr!=NULL){ 而(curr->line[i]!='\n'){ printf(“%c”,curr->line[i]); i++; } printf(“\n”); i=0; 当前=当前->下一步; } } /*分配一个新的textbuffer,其内容用给定的文本初始化 *在数组中。 */ TB newTB(字符文本[]){ 断言(文本!=NULL); int i=0; 字符c; TB tBuffer=malloc(sizeof(struct textbuffer)); tBuffer->size=0; //tNode*currLine=malloc(sizeof(struct textNode*)); tNode*currLine=newTN(NULL,1,NULL); tNode*currtNode; //currLine->line=malloc(sizeof(char));,c,debugging,C,Debugging,我在分配诸如“curr=curr->next”之类的内容时不断出错,我得到的第一个错误是: 在我声明静态函数newTN的行中,应在标记“*”之前加上“=”、“、”、“;”、“asm”或“属性”。请告诉我问题是什么……谢谢……在typedef struct textNode的定义中,您已经声明了struct textNode**next即next是的指针-指针或双指针。但在函数中静态tNode*newTN(char*string,int sLength,tNode*next);您已将next声明为

我在分配诸如“curr=curr->next”之类的内容时不断出错,我得到的第一个错误是:


在我声明静态函数newTN的行中,应在标记“*”之前加上“=”、“、”、“;”、“asm”或“属性”。请告诉我问题是什么……谢谢……在
typedef struct textNode
的定义中,您已经声明了
struct textNode**next
next
的指针-指针
双指针
。但在函数中
静态tNode*newTN(char*string,int sLength,tNode*next);
您已将
next
声明为
单指针

因此,在函数
static tNode*newTN(char*string,int sLength,tNode*next)的
t->next=next;
行中;
不能将
单指针
分配给
双指针

为解决此问题,在
typedef struct textNode
中声明
struct textNode**next
struct textNode*next
即为
单指针

更新:

struct textbuffer
的定义没有以

终止,谢谢。是的,我看到了,但我仍然收到了这个错误:在我声明静态函数newTN的行中,标记“*”之前应该有“=”、“、”、“;”、“;”、“asm”或“attribute”。发布后不久,我还编辑了双指针。@GCGSAUCE
的定义struct textbuffer
没有以
终止。我已经更新了相同的答案。
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "textbuffer.h"

typedef struct textNode{ //basically contains a line + link
    char* line;
    int sLength; //length of string
    struct textNode* next; 
} tNode; 

struct textbuffer{
    int size; //number of lines in the text buffer
    tNode* head; 
    tNode* tail;
}

static tNode* newTN(char* string, int sLength, tNode* next);

static tNode* newTN(char* string, int sLength, tNode* next){
    tNode* t = malloc(sizeof(struct textNode));
    t->line = malloc(sizeof(char)*sLength);

    if(string != NULL){
        strcpy(t->line, string);
    } 
    t->next = next; 
    return t;
}

static void printBuffer(TB tb){
    tNode* curr = tb->head;
    int i = 0;
    while(curr != NULL){

        while(curr->line[i] != '\n'){
            printf("%c", curr->line[i]);
            i++;
        }
        printf("\n");
        i = 0;
        curr = curr->next;
    }
}

/* Allocate a new textbuffer whose contents is initialised with the text given
 * in the array.
 */
TB newTB (char text[]){

    assert(text != NULL); 

    int i = 0; 
    char c;

    TB tBuffer = malloc(sizeof(struct textbuffer)); 
    tBuffer->size = 0; 

    //tNode* currLine = malloc(sizeof (struct textNode*));
    tNode* currLine = newTN(NULL, 1, NULL);
    tNode* currtNode; 

    //currLine->line = malloc(sizeof(char));