小编Tab*_*tha的帖子

c中的链表,意外结果

我是编程新手,我正在尝试学习链接列表.我决定通过编写一个简单的程序来试验链接列表,该程序将从文件中读取,一次一个字符,并将每个字符插入到链接列表中.然后我打印出链表.简单吧?好吧,也许不是,如果这是你第一次.我正在关注在线教程哦,如此仔细,但我的输出不是它应该是的.(程序编译并运行时没有错误或警告.我正在使用代码块.)我得到两个数字,而不是获取任何字符.

这是我写的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Tokens_read_in{
    char character;
    int number;
    char whichOne[5];
    struct Tokens_read_in* next;
}Tokens;

int main()
{

    //declare variables
    char c;

    //create a struct for the array that will hold the tokens
    Tokens* token_array;
    token_array = malloc(sizeof(Tokens));
    token_array->next = NULL;

    //open the input file
    FILE *ifp;  //input file pointer
    char *filename = "input.txt";
    ifp = fopen(filename, "r");

    if(!ifp){
        printf("Error in opening '%s' for reading!", filename);
        exit(0);
    }

    while(!feof(ifp)){

        //prepare to read in file …
Run Code Online (Sandbox Code Playgroud)

c linked-list

2
推荐指数
1
解决办法
205
查看次数

C程序中的EBNF声明语法

我对编程有点陌生(好吧,非常新),我遇到了扩展巴科斯诺尔范式(EBNF),并决定尝试弄清楚如何使用它。不幸的是,尽管网上有大量关于 EBNF 如何工作的解释,但关于如何实际实现它的却很少。所以我使用它用 C 语言编写了一个简单的小程序,只是为了看看会发生什么。这是我写的:

#include <stdio.h>
#include <stdlib.h>


mixture : [letter|digit] {letter | digit};
integer : [ "+"|"-"] digit {digit};
naturalNumber : digit {digit};
digit : "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
letter : "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" |    "n" | "o" | "p" | …
Run Code Online (Sandbox Code Playgroud)

c syntax declaration ebnf

0
推荐指数
1
解决办法
5792
查看次数

标签 统计

c ×2

declaration ×1

ebnf ×1

linked-list ×1

syntax ×1