RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-312060

dhvcc's questions

Martin Hope
dhvcc
Asked: 2020-08-29 07:51:26 +0000 UTC

Uvicorn、NGINX、Django

  • 1

我用于Django项目部署nginx和gunicorn

决定试试uvicorn

结果是运行,只是连接uvicorn,nginx什么都没有。

配置nginx

...

http {
    ...

    upstream uvicorn {
        server unix:/home/dhvcc/PycharmProjects/dwapper/dwapper.sock;
    }
}

项目配置

server {
    listen 80;
    server_name 0.0.0.0;

    return 301 https://0.0.0.0:80$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    # SSL
    ssl_certificate /etc/nginx/ssl/dwapper.crt;
    ssl_certificate_key /etc/nginx/ssl/dwapper.key;
    # DJANGO
    location = /favicon.ico {
        access_log off; log_not_found off;
    }
    location /static/ {
        alias /home/dhvcc/PycharmProjects/dwapper/staticfiles/;
    }
    # UVICORN
    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
        proxy_buffering off;
        proxy_pass http://uvicorn;
    }
}

当我尝试访问该站点时,我进入了日志

*205 connect() to unix:/home/dhvcc/PycharmProjects/dwapper/dwapper.sock failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/2.0", upstream: "http://unix:/home/dhvcc/PycharmProjects/dwapper/dwapper.sock:/", host: "localhost"

最有可能的问题是它uvicorn没有运行。我像这样运行它(--uds 明确指向该套接字)

/home/dhvcc/PycharmProjects/dwapper/venv/bin/uvicorn  --workers 3 --uds unix:/home/dhvcc/PycharmProjects/dwapper/dwapper.sock dwapper.asgi:application

由于某种原因,只有发射发生在http://127.0.0.1:8000.

dwapper.sock- 使用时生成的文件gunicorn

这是我工作的旧服务配置gunicorn

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=dhvcc
Group=www-data
WorkingDirectory=/home/dhvcc/PycharmProjects/dwapper
ExecStart=/home/dhvcc/PycharmProjects/dwapper/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/dhvcc/PycharmProjects/dwapper.sock dwapper.wsgi:application -k uvicorn.workers.UvicornWorker

[Install]
WantedBy=multi-user.target
python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-06-13 02:01:31 +0000 UTC

等待不起作用

  • 1

Beck on and Djangofront on clean JS/HTML/CSS什么都没有,但font awesome没用过。

对于测试,我完全重新启动服务器并Ctrl+Shift+R重置静态文件的缓存。

有这样的方法代码init

init() {
    document.addEventListener("DOMContentLoaded", async (event) => {
        console.log(`UserOffice init`);
        this.profile = await base.getProfile();
        console.log(`UserOfficeProfile is ${this.profile}`);
        ...
    });
}

方法代码getProfile

async getProfile() {
    const profile = await this.getXHRasync(`${window.location.origin}/api/get_profile/`)[0];
    console.log(`getProfile got ${profile}`)
    return profile;
}

和方法代码getXHRasync

getXHRasync(path) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', path, true);
        xhr.onload = function () {
            console.log(`GET XHR 2, path is ${path}, and response ${xhr.responseText}`);
            resolve(JSON.parse(xhr.responseText));
        };
        xhr.send();
    });
}

我不是专家JS,我只需要重构。据我了解,我await必须等待该值,然后才能继续执行代码。

但是我得到的排气。

好像到处都记下来了async/await,可能我有什么不知道的地方,指正

控制台日志

javascript
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-05-20 01:15:22 +0000 UTC

控制台中的问题而不是 unicode

  • 1

PyCharm 控制台 电源外壳

在这两个屏幕截图中,PyCharm 中的 powershell 和正常。问题是常规不能正确加载 unicode 字符

我试图通过更改编码$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8',但没有帮助

可以连接什么?

附加信息

  1. 更改chcp为 65001 没有帮助

  2. 如您所见,问题通常来自代码从 9600 到 9607、9608(常规块)输出的字符。唯一的问题是其余的在哪里

  3. 链接到程序输出

在此处输入图像描述

powershell
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-05-17 18:55:48 +0000 UTC

通过 TCP 发送长 utf8 消息

  • 0

我在上面写了一个客户端-服务器,并在TCPpython上写了一个小协议,以便更方便地发送消息

from json import dumps

def receive(socket):
    data = socket.recv(1024).decode('utf8')
    length = int(data[:16])
    data = data[16:]
    while length - 1:
        data += socket.recv(1024).decode('utf8')
        length -= 1
    return data


def send(socket, data):
    if type(data) == dict:
        data = chunk_string(dumps(data), 1000 - 16)
    else:
        data = chunk_string(str(data), 1000 - 16)
    length = len(data)
    data[0] = str(length).zfill(16) + data[0]
    for chunk in data:
        socket.send(bytes(chunk, encoding='utf8'))


def chunk_string(string, chunk_size):
    return [string[i:i + chunk_size] for i in range(0, len(string), chunk_size)]

发送时,数据被切割成每块 1000 个字符的块,块的数量被添加到前 16 个字符中。

原则上一切正常,但有一个问题:

多字节 unicode 字符。有时因为它们而receive崩溃UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data(字节的位置不完全是 1022-1023,在块的大小不是 1000 之前)

如何避免这个问题?现在,我设法发送普通字符,避免使用多字节字符,但是,当然,我也希望能够发送它们

python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-02-27 22:36:19 +0000 UTC

加入烧瓶-sqlalchemy

  • 0

有两个班

class Authors(db.Model):
    __tablename__ = 'authors'
    id = db.Column('id', db.Integer, primary_key=True)
    name = db.Column('name', db.String, nullable=False)

    def __init__(self, name):
        self.name = name


class Books(db.Model):
    __tablename__ = 'books'
    id = db.Column('id', db.Integer, primary_key=True)
    isbn = db.Column('isbn', db.String, nullable=False)
    title = db.Column('title', db.String, nullable=False)
    author_id = db.Column('author_id', db.Integer,
                          db.ForeignKey('authors.id'), nullable=False)
    year = db.Column('year', db.Integer)

    def __init__(self, isbn, title, author_id, year):
        self.isbn = isbn
        self.title = title
        self.author_id = author_id
        self.year = year

我想提出一个请求,但是在访问该元素时books=Books.query.all()我能达到什么Authors.namebooks

例如,我可以使用 books[x].title 获得书名,但我如何获得Authors.name?

我了解需要什么join,但我无法弄清楚语法,我看到了很多示例 for sqlalchemy,但不是 forflask-sqlalchemy

我不想要这样的语法db.session.query(Books,Authors).join()...

python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-02-21 00:07:11 +0000 UTC

Flask 不更新 CSS

  • 1

更新

更详细地研究了这个问题。CSS 在第一次运行时应用,但之后不会更改,即使您更新并保存文件。原则上,这对于文件夹来说听起来是合乎逻辑的static,但有些事情告诉我它不应该那样工作

问题

问题的本质是它CSS没有在服务器上更新Flask。h1一直是红色,如果已连接CSS,尽管CSS文件本身表明它应该是蓝色的

通过浏览器运行页面时,所有内容都已链接并且运行良好

原则上,一切都可以在视频中看到

尝试重新安装Flask,更改项目结构。项目文件夹中没有其他.css文件,但.scss它代表h1 { color: green; },原则上也不是红色的

资源

应用程序.py

from flask import Flask, render_template

app=Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

布局.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css')}}">
    <!-- <link rel="stylesheet" href="../static/style.css"> -->
    <title>Page</title>
</head>

<body>
    {%block body%}
    {%endblock%}
</body>

</html>

索引.html

{%extends "layout.html"%}

{%block body%}
    <h1>Hello!</h1>
{%endblock%}

样式.css

h1 {
  color: green;
}

/*# sourceMappingURL=style.css.map */
python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-01-28 09:16:56 +0000 UTC

如何停止 PyCharm 项目以触发 atexit?

  • 1

背景

我写了一个聊天机器人,当它启动时,它会发送有关其工作开始的消息,当它停止时,它会发送有关终止的消息

该机器人通过 LongPoll API 工作,因此仅通过关闭它ctrl+c并不方便,可能需要很长时间才能到达它KeyboardInterrupt(25 秒)

我通过运行代码shift+f10,即 在 PyCharm 中正常启动并停止ctrl+f2

退出设置

atexit.register(self.api.tell_all, data=self.data, message='Бот выключен')

PyCharm

停止时,PyCharm 说它用代码 -1 终止了进程,但atexit它不起作用。仅当您在代码中明确编写它时,它才exit(КОД)有效,或者当您收到异常时

问题

我是否以某种方式设置错误atexit并且一切都应该正常工作,或者 PyCharm 是否像那样杀死了这个过程?

希望能够通过触发器停止机器人,atexit而无需每次等待 25 秒

python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-01-23 07:37:07 +0000 UTC

pip 无法安装 python-magic

  • 3

点 20.0.1,设置工具 41.2.0

此问题仅在 Windows 上。最初,我在 Linux 和虚拟环境中编写所有内容并启动

安装程序.py

install_requires=['bs4',
                      'lxml',
                      'WeasyPrint',
                      'yattag',
                      'EbookLib',
                      'colorama',
                      'requests',
                      'python-magic'],

使用virtualenv并在setup.pypip install .旁边运行,一切似乎都可以正常下载。在启动时我得到

 File "c:\users\1337k\pycharmprojects\untitled1\v2\lib\site-packages\rss_reader\converting.py", line 3, in <module>
    import magic
  File "c:\users\1337k\pycharmprojects\untitled1\v2\lib\site-packages\magic.py", line 181, in <module>
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation

我用谷歌搜索,好像问题在python-magic- bin的帮助下得到了解决pip install python-magic-bin

ERROR: Could not find a version that satisfies the requirement python-magic-bin (from versions: none)
ERROR: No matching distribution found for python-magic-bin`

或者

pip uninstall python-magic
pip install python-magic-bin

 -> ERROR: Could not find a version that satisfies the requirement python-magic-bin (from versions: none)
ERROR: No matching distribution found for python-magic-bin

或者

pip uninstall python-magic
pip install python-magic-bin==0.4.14

-> ERROR: Could not find a version that satisfies the requirement python-magic-bin==0.4.14 (from versions: none)
ERROR: No matching distribution found for python-magic-bin==0.4.14

或者也许只是 pip install libmagic rss-reader(模块名称)?

-> pip install libmagic
Processing c:\users\1337k\appdata\local\pip\cache\wheels\68\33\a4\a404635e64d223a77f925132e51c1ccfdc32fd01d66b338f1a\libmagic-1.0-py3-none-any.whl
Installing collected packages: libmagic
Successfully installed libmagic-1.0
(v2) PS C:\Users\1337k\PycharmProjects\untitled1> rss-reader
Traceback (most recent call last):
  File "c:\users\1337k\appdata\local\programs\python\python38\Lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\1337k\appdata\local\programs\python\python38\Lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\1337k\PycharmProjects\untitled1\v2\Scripts\rss-reader.exe\__main__.py", line 4, in <module>
  File "c:\users\1337k\pycharmprojects\untitled1\v2\lib\site-packages\rss_reader\__main__.py", line 6, in <module>
    from rss_reader import converting
  File "c:\users\1337k\pycharmprojects\untitled1\v2\lib\site-packages\rss_reader\converting.py", line 3, in <module>
    import magic
ModuleNotFoundError: No module named 'magic'

附言

我不想失去对魔法的依赖,因为我只是修复了旧项目的依赖,我不想重写代码

PS2

如果有人可以提供正常的替代品,那么我在这里问。根据从 requests.get 收到的位确定类型很重要

python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-12-13 15:16:39 +0000 UTC

是否可以通过虚拟消除方法歧义?

  • 1
#include <iostream>
using namespace std;

class Student
{
public:
    Student() {}
    ~Student() {}
    void show()
    {
        cout << "Name: " << name << endl;
        cout << "Surname: " << surname << endl;
        cout << "Group: " << group << endl;
    }
    void set_name(string Name) { name = Name; }
    void set_surname(string Surname) { surname = Surname; }
    void set_group(string Group) { group = Group; }
protected:
    string name, surname;
    string group;
};

class Teacher
{
public:
    Teacher() : salary(0) {}
    ~Teacher() {}
    void show()
    {
        cout << "Name: " << name << endl;
        cout << "Surname: " << surname << endl;
        cout << "Degree: " << degree << endl;
        cout << "Salary: " << salary << endl;
    }
    void set_name(string Name) { name = Name; }
    void set_surname(string Surname) { surname = Surname; }
    void set_degree(string Degree) { degree = Degree; }
    void set_salary(double Salary) { salary = Salary; }
protected:
    string name, surname;
    string degree;
    double salary;
};

class Undergraduate : public Student
{
public:
    Undergraduate() {}
    ~Undergraduate() {}
};

class Postgraduate: virtual public Undergraduate
{
public:
    Postgraduate() {}
    ~Postgraduate() {}
};

class TeachingAssistant: public Teacher, public Postgraduate
{
public:
    TeachingAssistant(){}
    ~TeachingAssistant(){}
};


int main()
{
    TeachingAssistant ta;
    ta.show();
}

在这样的一段代码中,需要消除方法显示的歧义,set_name_set_surname

似乎我试图vritual在几乎所有地方替换继承,但它仍然不起作用。据我所知,virtual当某些东西被继承两次但它是同一个基类的成员时,它有助于消除歧义。

如果virtual方法来自不同的类,但名称不同,会有帮助吗?如果没有,最好的方法是什么?

c++
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-12-04 22:37:43 +0000 UTC

按字符串字段对对象数组进行排序

  • 0

有这样一个管理员类

class Admin
{
public:
    Admin() {}
    Admin(string log, string pass): login(log), password(pass) {}
    ~Admin() {}
    string get_login() { return login; }
    string get_password() { return password; }
    static int a_Login(string Login, string Password);
    static void a_Menu();
    static void a_print();
    static void a_delete();
    static void a_add();
    static void a_edit();
    static void a_sort(int ascend=1);
    static void load_data();
    static void read_admins();
    static void write_admins();
    static string current_admin;
protected:
    static int ascend_comp_login(const void* a, const void* b);
    static int descend_comp_login(const void* a, const void* b);
    string login, password;
};

还有这样的比较器和方法本身,它调用 qsort

int Admin::ascend_comp_login(const void* a,const void* b)
{
    string l = ((Admin*)a)->get_login();
    string r = ((Admin*)b)->get_login();
    return l.compare(r);
}
int Admin::descend_comp_login(const void* a, const void* b)
{
    string l = ((Admin*)a)->get_login();
    string r = ((Admin*)b)->get_login();
    return r.compare(l);
}
void Admin::a_sort(int ascend)
{
    if (ascend) qsort(&admins, admins.size(), sizeof(Admin), ascend_comp_login);
    else qsort(&admins, admins.size(), sizeof(Admin), descend_comp_login);
    Admin::a_print();
}

admins 是类型的向量vector<Admin>

经过这样的转换,首先登录,然后回到管理员,显然,infa丢失了。getter 返回随机垃圾或空字符串

我该如何解决这个问题,以便最终可以使用它qsort?

c++
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-11-30 22:55:56 +0000 UTC

如何通过测试找出代码覆盖率?

  • 1

我使用 unittest 进行测试。我正在运行 pytest。如何通过测试找出代码覆盖率?似乎coverage.py可以以某种方式使用?

python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-11-17 20:00:10 +0000 UTC

无法摆脱 json.dumps 中的 unicode

  • 1
def print_json(limit, soup):
    feed = html.unescape(soup.title.text)
    dict_json = {feed: {}}
    items = soup.findAll('item')
    for i in items:
        dict_json[feed] = {'Title': html.unescape(i.title.text), 'Date': html.unescape(i.pubDate.text),
                           'Link': html.unescape(i.link.text)}
    print(json.dumps(dict_json, indent=4))

当我启动程序时,我得到

{
    "TUT.BY: \u041d\u043e\u0432\u043e\u0441\u0442\u0438 \u0422\u0423\u0422 - \u0413\u043b\u0430\u0432\u043d\u044b\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438": {
        "Title": "\u0421 \u041b\u0435\u043d\u0438\u043d\u044b\u043c \u0432 \u0441\u0435\u0440\u0434\u0446\u0435 \u0438 \u0433\u0432\u043e\u0437\u0434\u0438\u043a\u0430\u043c\u0438 \u0432 \u0440\u0443\u043a\u0430\u0445. \u041a\u0430\u043a \u0432 \u041c\u0438\u043d\u0441\u043a\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u043b\u0438 \u0433\u043e\u0434\u043e\u0432\u0449\u0438\u043d\u0443 \u041e\u043a\u0442\u044f\u0431\u0440\u044c\u0441\u043a\u043e\u0439 \u0440\u0435\u0432\u043e\u043b\u044e\u0446\u0438\u0438",
        "Date": "Thu, 07 Nov 2019 15:36:00 +0300",
        "Link": "https://news.tut.by/economics/660484.html?utm_campaign=news-feed&utm_medium=rss&utm_source=rss-news"
    }
}

虽然,例如,标题应该是“TUT.BY: News HERE - Main News” 为什么结果有些行正常,有些行不正常?

python
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-11-16 13:25:28 +0000 UTC

将 string[] 传递给函数而不使用变量

  • 1
string Strings[100];
...
    case 1:
        Strings[0] = "1)Электронный каталог\n";
        Strings[1] = "2)Заказ услуги\n";
        Strings[2] = "3)Новости и объявления\n";
        Strings[3] = "4)О нас\n";
        Strings[4] = "5)Назад\n";
        switch (menu.Start(5, "\tМеню гостя\n", Strings ))
        {
        }
        break;

有没有办法在不使用变量的情况下将相同的字符串传递给函数Strings, типа {"1)", "2)"}?

不一定要用string[],也可以用char*[]

c++
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-10-15 03:58:30 +0000 UTC

如何从函数访问全局变量

  • 0

如何从已经具有同名变量的函数访问全局变量?假设有一个程序

#include <iostream>
int q=15;
void main()
{
    int q=10;
    std::cout<<q<<endl;
}

怎么能引用全局 q?

c++
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-10-02 19:41:17 +0000 UTC

将客户端连接到 TCP/IP 服务器时出错

  • 0

无法在 Linux Mint 上通过 tcp/ip 在服务器和客户端之间创建连接。通过 gcc.Connect 编译返回 -1 并且 errno 给出 ECONNREFUSED。之前这个服务器只在 Windows 上使用 winsock2 编写。服务器

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <netinet/in.h>

#include <iostream>
#include <unistd.h>
#include <iomanip>
#include <string.h>
using namespace std;

int main()
{
    int s,s2,bl;
    s=socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in local;
    local.sin_port=htonl(7500);
    local.sin_family=AF_INET;
    local.sin_addr.s_addr=htonl(INADDR_ANY);
    bl=bind(s,(struct sockaddr*)&local,sizeof(local));
    cout<<"Listen\n";
    bl=listen(s,5);
    cout<<"Accept\n";
    s2=accept(s,0,0);
    send(s2,"HW",sizeof("HW"),0);
}

客户

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#include <iostream>
#include <unistd.h>
#include <iomanip>
#include <string.h>
using namespace std;
int main()
{
    int s,rc;
    s=socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in peer;
    peer.sin_family=AF_INET;
    peer.sin_port=htons(7500);
    peer.sin_addr.s_addr=inet_addr("127.0.0.1");
    cout<<"Connecting\n";
    rc=connect(s,(struct sockaddr*)&peer,sizeof(peer));
    switch (errno)
    {
    case EACCES:
        fprintf(stdout, "EACCESS");
        break;
    case EPERM:
        fprintf(stdout, "EPERM");
        break;
    case EADDRINUSE:
        fprintf(stdout, "EADDRINUSE");
        break;
    case EAFNOSUPPORT:
        fprintf(stdout, "EAFNOSUPPORT");
        break;
    case EAGAIN:
        fprintf(stdout, "EAGAIN");
        break;
    case EALREADY:
        fprintf(stdout, "EALREADY");
        break;
    case EBADF:
        fprintf(stdout, "EBADF");
        break;
    case ECONNREFUSED:
        fprintf(stdout, "ECONNREFUSED");
        break;
    case EFAULT:
        fprintf(stdout, "EFAULT");
        break;
    case EINPROGRESS:
        fprintf(stdout, "EINPROGRESS");
        break;
    case EINTR:
        fprintf(stdout, "EINTR");
        break;
    case EISCONN:
        fprintf(stdout, "EISCONN");
        break;
    case ENETUNREACH:
        fprintf(stdout, "ENETUNREACH");
        break;
    case ENOTSOCK:
        fprintf(stdout, "ENOTSOCK");
        break;
    case ETIMEDOUT:
        fprintf(stdout, "ETIMEDOUT");
        break;
    default:
        fprintf(stdout, "unknown error(%d)", errno);
        break;
    }
    cout<<endl;
    char choice[100];
    char buf[100];
    recv(s,buf,sizeof("HW"),0);
}
c++
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-04-05 00:16:19 +0000 UTC

检查菜单中箭头的点击

  • 0
    char choice;
    int start_menu_toggle[4];
    register int i,j,k;
    for (i=0;i<4;i++){
        start_menu_toggle[i]=7;
    }
    int tmp=3;
    start_menu_toggle[tmp]=240;
    system("cls");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
    printf("\tВход\n");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[3]);
    printf("Вход как главный администратор\n");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[2]);
    printf("Вход как администратор\n");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[1]);
    printf("Вход как пользователь\n");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[0]);
    printf("Выход\n");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
    for (choice=getch();choice!='\r';choice=getch()){
        if (choice==0xE0 || choice==0 || choice==224){
        printf("Arrow key\n");
        system("pause");
        }
        choice=getch();
        if (choice!=72 && choice!=80){
        continue;
        }
        switch (choice){
            case 72:
                if (tmp<3){
                    start_menu_toggle[tmp]=7;
                    tmp++;
                    start_menu_toggle[tmp]=240;
                }
                break;
            case 80:
                if (tmp>0){
                    start_menu_toggle[tmp]=7;
                    tmp--;
                    start_menu_toggle[tmp]=240;
                }
                break;
        }
        system("cls");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
        printf("\tВход\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[3]);
        printf("Вход как главный администратор\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[2]);
        printf("Вход как администратор\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[1]);
        printf("Вход как пользователь\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), start_menu_toggle[0]);
        printf("Выход\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
    }
    switch (tmp){
        case 3:
            enter_perm='s';
            if (enter()){
                ban_flag=0; ban_count=0; ban_time=0; ban_flag_refresh();
                a_menu();
            } else{
                    ban_count++; 
                    ban_flag_refresh(); 
                    printf("Ошибка входа\nОсталось попыток %d\n", 3-ban_count); 
                    system("pause"); 
                    start_menu();
                }
            break;
        case 2:
            enter_perm='a';
            if (enter()){
                ban_flag=0; ban_count=0; ban_time=0; ban_flag_refresh();
                a_menu();
            } else{
                    ban_count++; 
                    ban_flag_refresh(); 
                    printf("Ошибка входа\nОсталось попыток %d\n", 3-ban_count); 
                    system("pause"); 
                    start_menu();
                }
            break;
        case 1:
            enter_perm='u';
            if (enter()){
                ban_flag=0; ban_count=0; ban_time=0; ban_flag_refresh();
                u_menu();
            } else{
                    ban_count++; 
                    ban_flag_refresh(); 
                    printf("Ошибка входа\nОсталось попыток %d\n", 3-ban_count); 
                    system("pause"); 
                    start_menu();
                }
            break;
        case 0:
            printf("Выбран выход из программы\n");
            sleep(1);
            exit(1);
    }

你好。这是我的登录功能的代码。使用向上/向下箭头时,一切正常,但是当您按任何其他键(甚至不是向左/向右箭头)时,菜单将不起作用,直到您再次按下任何键而不是箭头。似乎以某种方式您可以从第一个 getch 中检查索引,但是

c
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-03-22 21:49:02 +0000 UTC

结构数据输出

  • -1
关闭 这个问题是题外话。目前不接受回复。

该问题是由不再复制的问题或错字引起的。虽然类似的问题可能与本网站相关,但该问题的解决方案不太可能帮助未来的访问者。通常可以通过在发布问题之前编写和研究一个最小程序来重现问题来避免此类问题。

3年前关闭。

改进问题
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

struct foo_predmet{
    char name[30];
    int score;
    int variant;
};

struct foo_gde{
    char name[30];
    char auditoriya;
    char vremya;
};

typedef struct foo_abitur{
    char fio[30];
    struct foo_predmet predmet[4];
    struct foo_gde gde;
    struct foo_abitur *next;
} abitur1;

abitur1 abitur[10];


int main(void){
    SetConsoleCP (1251);
    SetConsoleOutputCP (1251);
    fflush(stdin);
    gets(abitur[0].gde.name);
    printf("%s\n" abitur[0].gde.name);
    return 0;
}

程序代码。问题是,为什么它会给我一个错误“预期是')'”?我试图使这个数组成为指针并动态分配内存,都一样

c
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-03-06 04:53:43 +0000 UTC

用星号隐藏密码的问题

  • 0

编写了一个读取密码的代码,并在您按 Enter 时将其打印出来。提供退格

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

int main(void){
    SetConsoleCP (1251);
    SetConsoleOutputCP (1251);
    char password[100],c;
    int i;
    i=0;
    while ((password[i]=getch())!='\r'){
        if (password[i]=='\b' && i!=0){
            printf("%s", "\b \b");
            i--;
            continue;
        }
        printf("%c", '*');
        i++;
    }
    printf("\npassword is %s\n", password);
return 0;
}

问题在结论中。

Вывод при пароле "qwe"(звездочки это еще ввод самого пароля)
***
\
 r╗Мюad is qwe

.

Вывод при пароле qwerty
******
╗Мюaword is qwerty

.

Вывод при пароле qwertyuiop
**********
password is qwertyuiop

无论是否使用退格,输出都不会改变。你能提出什么问题吗?

c
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-03-03 17:02:45 +0000 UTC

传递指向结构的指针

  • 0

无法将指针传递给结构

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

void Print(qweptr strct){
    printf("%d\n", strct->data);
    return;
}

int main(void){
    SetConsoleCP (1251);
    SetConsoleOutputCP (1251);
    struct sh{
        int data;
    };
    typedef struct sh qwe; //qwe = struct sh
    typedef qwe* qweptr;// qweptr = qwe* = struct sh*
    qweptr start; // создаю struct sh *start
    if (!(start=(qweptr)malloc(1*sizeof(qwe)))){
        puts("Not enough memmory!\n");
        return 0;
    }
    start->data=10;
    Print(start);
return 0;
}

请告诉我,错误是什么?

c
  • 1 个回答
  • 10 Views
Martin Hope
dhvcc
Asked: 2020-02-22 00:06:45 +0000 UTC

宏定义

  • 4

在做实验的过程中,我遇到了一个任务,你只需要编写一个程序来计算矩阵的乘积,同时动态分配内存。听起来很简单,但最后我发现了这个

创建宏定义,计算程序使用动态内存分配和释放函数的次数,以及分配和释放的内存量。

除了关于#define、#if 等的解释外,培训手册中没有任何内容。我想知道它是关于什么的)

c
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5