|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 bin554385863 于 2019-7-16 19:08 编辑
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct Node
- {
- int value;
- struct Node *next;
- } node;
- void ptf(node *str)
- {
- int i = 0;
- while (str[i].value != -1)
- {
- i++;
- printf("%d\n", str[i].value);
- }
- };
- node *creatlink(node *str)
- {
- int i = 0;
- while (str[i].value != -1)
- {
- i++;
- scanf("%d", &str[i].value);
- str[i].next = &str[i + 1];
- }
- str[i + 1].next = NULL;
- str[i + 1].value = NULL;
- return str;
- };
- int main(int argc, char const *argv[])
- {
- node *snum;
- snum = (node*)malloc(sizeof(node));
- int num, i = 0;
- creatlink(snum);
- printf("\n");
- ptf(snum);
- //free(snum);
- return 0;
- }
复制代码
-------------------------------------------------------------------------------------------------Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
E:\Administrator\Documents\My C>cmd /C "c:\Users\Administrator\.vscode\extensions\ms-vscode.cpptools-0.24.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-qkc1vvjj.ur2 --stdout=Microsoft-MIEngine-Out-3hjy3zd0.mu2 --stderr=Microsoft-MIEngine-Error-novtgcf4.5zz --pid=Microsoft-MIEngine-Pid-ngijy03t.fxn --dbgExe=E:\MinGW\bin\gdb.exe --interpreter=mi "
E:\Administrator\Documents\My C>cmd /C "c:\Users\Administrator\.vscode\extensions\ms-vscode.cpptools-0.24.0\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-d2hrcxrw.hkb --stdout=Microsoft-MIEngine-Out-iqhqpbne.dc3 --stderr=Microsoft-MIEngine-Error-riz3v2nk.nze --pid=Microsoft-MIEngine-Pid-bjeqejsu.3w1 --dbgExe=E:\MinGW\bin\gdb.exe --interpreter=mi "
99
66
5
3
-1
99 66 5 3 -1
=================================================================
突发奇想用结构数组写一个链表
可以正确输入输出
但是还有一堆莫名其妙的bug
你申请内存大小出错了
大概这么写吧
const int SIZE = 爱写多少写多少
Node *snum = (Node*)malloc(sizeof(Node) * SIZE);
内存分配没学好等于没学过C语言
|
|