大一c,求大佬救救我吧
我想要在循环中逐次输入字符,就类似一个小计算器,但运行后我就输入了一次电脑直接运行完了,求助大佬,好人一生平安!!!#include <stdio.h>#include <stdlib.h>
int main()
{
char c;
int iCounter;
iCounter = 1;
do
{
printf("Input your code\n");
c = getchar();
c = c + 4;
printf("Its real code is %c",c);
++iCounter;
}while(iCounter <= 5);
return 0;
} 本帖最后由 jackz007 于 2020-10-19 17:46 编辑
#include <stdio.h>
int main(void)
{
char c ;
int iCounter = 1 ;
printf("Input your code : ") ;
do {
if((c = getchar()) != '\n') {
if(iCounter == 1) printf("Its real code is : ") ;
printf("%c" , c + 4) ;
iCounter ++ ;
} else {
break ;
}
} while(iCounter <= 5) ;
printf("\n") ;
} 也许,这个代码更加实用
#include <stdio.h>
char encrypt(char c)
{
if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
if(c >= 'W' && c <= 'Z' || c >= 'w' && c <= 'z' || c >= '6' && c <= '9') {
if(c >= 'W' && c <= 'Z' || c >= 'w' && c <= 'z') c -= 26 ;
else c -= 10 ;
}
c += 4 ;
}
return c ;
}
char decrypt(char c)
{
if(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
if(c >= 'A' && c <= 'D' || c >= 'a' && c <= 'd' || c >= '0' && c <= '3') {
if(c >= 'A' && c <= 'D' || c >= 'a' && c <= 'd') c += 26 ;
else c += 10 ;
}
c -= 4 ;
}
return c ;
}
int main(void)
{
char c ;
int iCounter = 1 ;
printf(" Input your code : ") ;
do {
if((c = getchar()) != '\n') {
if(iCounter == 1) printf("Its real code is : ") ;
printf("%c" , encrypt(c)) ;
iCounter ++ ;
} else {
break ;
}
} while(true) ;
printf("\n") ;
iCounter = 1 ;
printf(" Input your code : ") ;
do {
if((c = getchar()) != '\n') {
if(iCounter == 1) printf("Its real code is : ") ;
printf("%c" , decrypt(c)) ;
iCounter ++ ;
} else {
break ;
}
} while(true) ;
printf("\n") ;
}
下面是编译、运行实况:
D:\00.Excise\C>g++ -o x4 x4.c
D:\00.Excise\C>x4
Input your code : Hello , I Love You !
Its real code is : Lipps , M Pszi Csy !
Input your code : Lipps , M Pszi Csy !
Its real code is : Hello , I Love You !
D:\00.Excise\C>
jackz007 发表于 2020-10-19 17:32
谢谢大佬!!!! jackz007 发表于 2020-10-19 18:28
也许,这个代码更加实用
下面是编译、运行实况:
大佬,我刚大一学c,就上了4节,您这代码我有点懵呀{:10_266:}
不过谢谢您又写了一个,麻烦您了,谢谢!!!
页:
[1]