- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
大家好,我正在做一个类(class)项目,将文件中的单词添加到 trie 中,将其与另一个文件进行比较并显示某些信息。我似乎无法弄清楚为什么会出现这些错误。在我的 dictstat.c 文件中,这是我的代码。
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ctype.h>
4 #include "prototypes.h"
5
6 typedef struct TrieNode
7 {
8 int isAWord ;
9 char letter;
10 int words;
11 struct TrieNode* children[26];
12 }Node;
13
14 typedef struct TrieADT
15 {
16 Node* root;
17 }MainTrie;
18
19 int main(int argc, char *argv[]){
20
21 MainTrie FirstTrie;
22 MainTrie *Trie;
23 Trie = &FirstTrie;
24
25 FILE *f, *f2;
26
27 if(argc != 3){
28 return 1;
29 }
30
31 f = fopen(argv[1], "r");
32 f2 = fopen(argv[2], "r");
33
34 if(f == NULL || f2 == NULL){
35 return 1;
36 }
37
38 makeTrie(Trie);
39
40 return 0;
41 }
42
43
44 Node *getNode(void) {
45
46 int i;
47 Node *newNode = NULL;
48 newNode = (Node *) malloc(sizeof(Node));//allocates space for new node
49 newNode->isAWord = 0;
50 newNode->letter = '/';
51
52 if( newNode ){
53
54 for(i = 0; i < 26; i++){
55
56 newNode->children[i] = NULL;//Sets elements in array equal to Null
57
58 }
59 return newNode;
60 }
61 }
62
63
64 void makeTrie(MainTrie *pTrie){
65
66 pTrie->root = getNode();
67 }
68
69 int addToTrie(char word[], int lengthOfWord, Node *TNode, int point){
70
71 if(lengthOfWord == 0){//if the length of the word is 0 stop the function
72
73 printf("No word.\n");
74 return 0;
75 }
76
77 if(point >= lengthOfWord){//if the pointer is beyond the end of a word
78
79 TNode->isAWord = 1;//then set the node to be the end of the word
80 return 1;
81 }
82
83 if(TNode == NULL){//if Node is null end function
84
85 printf("Pointer is null.\n");
86 return 0;
87 }
88
89 if( TNode->children[(word[point])-'a'] == NULL ){//if there is no neighbor with letter
90
91 Node *newNode;
92 newNode = getNode();//Makes new node
93 newNode->letter = word[point];//Puts letter in new node
94 TNode->children[(word[point])-'a'] = newNode;//puts new node into trie
95 point = point + 1;//increments down the tree
96 printf("adding\n");
97 return addToTrie(&word[point-1], lengthOfWord, TNode->children[(word[point]) - 'a'], point);//Calls function again
98 }
99
100 else{
101
102 printf("There is a neighbor.");//No new node to create
103 return addToTrie(&word[point-1], lengthOfWord, TNode->children[(word[point]) - 'a'], point);
104 }
106
107 }
108 }
这是我的 prototypes.h 文件。
1 void readDict(FILE* dict_file);
2 void scanData(FILE* data_file);
3 void makeTrie(MainTrie *pTrie);
4 int addToTrie(char word[], int lengthOfWord, Node* TNode, int point);
当我尝试同时编译 .c 文件和 .h 文件时,我收到以下错误消息:
In file included from dictstat.c:4:
prototypes.h:3: error: expected ‘)’ before ‘*’ token
prototypes.h:4: error: expected declaration specifiers or ‘...’ before ‘Node’
dictstat.c:64: warning: conflicting types for ‘makeTrie’
dictstat.c:38: note: previous implicit declaration of ‘makeTrie’ was here
dictstat.c:69: error: conflicting types for ‘addToTrie’
prototypes.h:4: note: previous declaration of ‘addToTrie’ was here
prototypes.h:1: error: expected ‘)’ before ‘*’ token
prototypes.h:2: error: expected ‘)’ before ‘*’ token
prototypes.h:3: error: expected ‘)’ before ‘*’ token
prototypes.h:4: error: expected declaration specifiers or ‘...’ before ‘Node’
我是新来的,所以如果我搞砸了这个问题的格式或者已经回答了,我深表歉意。提前致谢。
最佳答案
您在源文件中定义类型 MainTrie
(和 TrieNode
),但在头文件(在函数原型(prototype)中)中包含对它们的引用。
解决方案:将 typedef
/struct
声明移动到头文件。
关于c - 在 ')' token 和 '*' 的冲突类型之前预期为 'function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26246397/
我正在寻找一种使此打印 HTML 代码 fragment 向后兼容旧 Android 版本的简单方法: @TargetApi(Build.VERSION_CODES.KITKAT) private v
我在 GCC 终端 (centos linux) 中为 ATM 项目编译以下 c 和 .h 代码时收到以下错误。请帮忙,因为我是编程新手。 validate_acc.h #ifndef _VALIDA
在写关于 SO 的不同问题的答案时,我制作了这个片段: @import url('https://fonts.googleapis.com/css?family=Shadows+Into+Light'
试图弄清楚我应该如何在 my_div_class 之前放置一个 span 而不是替换所有它。现在它取代了 div,但我不想这样做。我假设它类似于 :before 但不知道如何使用它。 { va
我正在使用选择库 http://github.hubspot.com/select/和 noUiSlider https://refreshless.com/nouislider/ .我面临的问题如下
我是开发新手,独自工作。我正在使用 Xcode 和 git 版本控制。可能我没有适本地组织和做错事,但我通常决定做 promise 只是为了在我破坏一切之前做出安全点。在那一刻,我发现很难恰本地描述我
我想确保在同一个桶和键上读取和写入时,应该更新获取的值,也就是说,应该在对其进行写入操作之后获取它。我怎样才能做到这一点? 我想要的是,如果我更新一个键的值,如果我同时使用不同线程获取值,则更新同一个
我的问题与this有关问题,已经有了答案: yes, there is a happens-before relationship imposed between actionsof the thre
The before and after hook documentation on Relish仅显示 before(:suite) 在 before(:all) 之前调用。 我什么时候应该使用其中
我有 CSV 行,我想在其中检测所有内部双引号,没有文本限定符。这几乎可以正常工作,但我的正则表达式还可以检测双引号后的字符。 CSV 部分: "7580";"Lorem ipsum";"";"Lor
是否可以通过Youtube数据API检查广告是否可以与特定视频一起显示? 我了解contentDetails.licensedContent仅显示视频是否已上传至同一伙伴然后由其声明版权。由于第三者权
考虑一下用漂亮的彩色图表描述的“像素管道” https://developers.google.com/web/fundamentals/performance/rendering/ 我有一个元素(比
之前?
在 MVC3 中,我可以轻松地将 jQuery 脚本标签移动到页面底部“_Layout.vbhtml” 但是,在 ASP.NET MVC3 中,当您使用编辑器模板创建 Controller 时,脚手
悬停时内容被替换,但是当鼠标离开元素时我希望它变回来。我该怎么做? $('.img-wrap').hover(function(){ $(this).find('h4').text('Go
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码以重现该问题。
版本:qwt 6.0.1我尝试开发频谱的对数缩放。我使用简单的线条来启用缩放plotspectrum->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10S
我有两个相同的表,I_Subject 和 I_Temp_Subject,我想将 Temp_Subject 表复制到 Subject 表。 I_Temp_Subject 由简单用户使用,I_Subjec
我的印象是第一次绘制发生在触发 DOMContentLoaded 事件之后。特别是,因为我认为为了让第一次绘制发生,需要渲染树,它依赖于 DOM 构造。另外,我知道 DOM 构造完成时会触发 DOMC
我是一名优秀的程序员,十分优秀!