#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Test9
{
char name[50];
int id;
struct Test9* Nest;
}Test;
//头节点
Test* createhead(){
Test* head = (Test*)malloc(sizeof(Test));
head->Nest = NULL;
return head;
}
//初始化节点
Test* createNode(char* name,int n){
Test* newNode = (Test*)malloc(sizeof(Test));
strcpy(newNode->name,name);
newNode->id = n;
newNode->Nest = NULL;
return newNode;
}
//创建链表
Test* create(Test* head,int n){ //n为节点数
Test* p = head;
int i = 0;
char address[20];
printf("请输入张敏北京一日游观光的地点:");
while(i<n){
i++;
scanf("%s",&address);
Test* Node = createNode(address,i);
p->Nest = Node;
p = Node;
}
return p;
}
//输出链表
void printLink(Test* head,int n){
Test* p = head;
while (p ->Nest != NULL)
{
printf("the NO%d member is:\n",p->Nest->id);
printf("地点是:%s\n",p->Nest->name);
printf("第%d个参观\n",p->Nest->id);
printf("\n");
p = p->Nest;
}
}
int main()
{
int n = 3;
Test* link = createhead();
create(link,n);
printLink(link,n);
return 0;
}
vs code终端不能输出中文,
在vscode的设置里,将编码方式修改为UTF-8,就能显示中文了。
file->preferences->settings,然后按下图设置:
直接就将代码保存为gb2312。在vs code右下角可以看到当前文件编码方式,点击utf-8修改打开和保存方式为gb2312.
在vscode终端中正确输出中文字符,需要设定终端的编码格式为utf-8,并在代码中指明字符编码为utf-8。具体步骤如下:
打开vscode终端,并输入以下命令:
bash chcp 65001
这个命令将终端的编码格式设置成UTF-8。
在代码文件中设置字符编码为utf-8,可以在代码文件前加入以下注释:
```python
```
或者在代码开始前指定字符编码:
```python
#!/usr/bin/env python
# coding=utf-8
```
对于其他编程语言也可以对应的设置,具体可以参考各语言官方文档。
在写入文件时,指明编码为utf-8:
python with open('test.txt', 'w', encoding='utf-8') as f: f.write('你好')
如果以上步骤中没有出现错误,就可以正确输出中文字符了。
注意,在Windows系统中,cmd终端默认使用gbk编码,所以在cmd终端中输出中文字符时可能会出现乱码。因此,在Windows系统中,最好使用git bash或者PowerShell终端,这些终端会默认使用UTF-8编码。