Ctrl+D doesn't stop application from executing in command window

前端 未结 5 891
后悔当初
后悔当初 2020-12-07 05:21

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 :

void         


        
5条回答
  •  感动是毒
    2020-12-07 05:42

    isprint() can help:

    #include 
    #include 
    
    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;
    }
    

提交回复
热议问题