注册 登录
编程论坛 C++教室

帮忙解决一下“输入一行字符,要就输出其相应的密码”谢谢

灵树 发布于 2010-04-13 23:59, 677 次点击
帮忙解决一下“输入一行字符,要就输出其相应的密码”谢谢
4 回复
#2
cnfarer2010-04-14 09:58
#include<iostream>
using namespace std;
void main()
{
   char c, str[100];
   int i=0;
   printf("Input : ");
   while((c=getchar())!='\n')
    {
       str[i++]=c+10;
   }
   str[i]='\0';
     printf("Output: ");
     printf("%s\n",str);
}
#3
asdjc2010-04-17 12:52
我觉得应该告诉我们要用的是那种密码吧?
二楼的cnfarer高手写的是进十处理的密码。(好像有点不好的地方,str[i++]=c+10
                                                         改为str[i++]=(c+10)%26会不会好点?)
#4
yyblackyy2010-04-20 00:31
#include<stdio.h>
#include<conio.h>
#define Max 100
int main()
    {
    char str[Max];
    char ch,*ps=str;
        for(;;)
            {
            if(kbhit())
                {
                    ch=getch();
                    if(ch=='\r')
                        {
                        *ps='\0';
                        break;
                    }
                    else
                        {
                        *ps++=ch;
                        putchar('*');
                    }
                else                 //减少系统的CPU的,不知道则么写
                    {
                        ;          //运行还可以,就是这个CPU。。。高了
                    }
            }
        
        }
        printf("\n%s\n",str);
        ps=0;        
    return 0;
}
#5
yyblackyy2010-04-20 14:35
#include<stdio.h>                         //这个不太占用太多的CPU
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int main()
    {
    char ch,str[512],*p=str;
   
    while(ch=getch())
        {    unsigned count=0;
            if(ch=='\10')
                {
                system("cls");
            
                if(strlen(str))
                    {   
                    *(--p)=0;
                    count=strlen(str);
                    for(unsigned i=0;i<count;i++)
                    putch('*');
                }
                continue;
            }
            if(ch=='\n'||ch=='\r')
                {
                /*    *p++='\n';           去掉注释符和break 的话 Enter键也能使了,用F某某键跳出
                    *p=0;
                    putch('*');
                    continue;
                    */
                break;
            }
            *p++=ch;
            *p=0;
            putch('*');            
    }
    system("cls");
    printf("%s\n",str);
    return 0;
}
1