按Ctrl + D不能从命令窗口中执行应用程序停止 [英] Ctrl+D not stopping application from executing in command window

查看:144
本文介绍了按Ctrl + D不能从命令窗口中执行应用程序停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序通过XOR加密一个给定的消息。它的工作原理,但它并没有结束。这里是code(我已经创建了3个文件):

I've written a program to encrypt a given message by XOR. It works, but It doesn't end. Here is the code.(I have created 3 files):

encrypt.h:

encrypt.h :

void encrypt(char *message);

message_hider.c:

message_hider.c:

#include <stdio.h>
#include "encrypt.h"

int main() {
  char msg[80];

  while (fgets(msg, 80, stdin)){
    encrypt(msg);
    printf("%s", msg);
  }

  return 0;
}

encrypt.c:

encrypt.c :

#include "encrypt.h"

void encrypt(char *message) {
  while (*message) {
    *message++ ^= 0x1f;
  }
}

正如我上面提到的,它的工作原理。但我不能阻止它。当我pressed Ctrl + D键来阻止它(在CMD)也进行加密。(我需要这个code终止后,加密信息)。请给我解释一下这个案子。

As I mentioned above, It works. but I can't stop it. When I pressed Ctrl+D to stop it (in cmd) It encrypts it also.(I need this code stop after it encrypt a message). Please explain me about this case.

推荐答案

isprint判断()可以帮助:

#include <stdio.h>
#include <ctype.h>

void encrypt(char *message)
{
    while (*message) {
        *message = *message ^ 31;
        message++;
    }
}

int main(void)
{
    char msg[80];

    while (fgets(msg, 80, stdin) != NULL) {
        if (!isprint((unsigned char)*msg)) break;
        encrypt(msg);
        printf("%s", msg);
    }
    return 0;
}

这篇关于按Ctrl + D不能从命令窗口中执行应用程序停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆