- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的任务是创建一个移位密码,从用户那里获取一个字符串,然后加密、解密、移动移位变量或退出。我编写的代码在 Atom 中完美运行,但是当我在 VIM 中尝试它时(我必须从其中提交代码),一切正常,除了:每当我的加密或解密函数运行时,输出都是空白的。
int main(){
int shift = 3;
char stringresponse[SIZE];
while (1 || 2 || 3){
switch(getUserChoice()){
case 1:
shift = getShift();
break;
case 2:
getString(stringresponse);
encrypt(stringresponse,shift);
break;
case 3:
getString(stringresponse);
decrypt(stringresponse,shift);
break;
default :
printf("Exiting the program");
exit(0);
}
}
return 0;
}
int getUserChoice(){
int userchoice = 0;
char dump = 0;
printf("--------------------------------\n");
printf("| 1) Change Shift (Default 3) |\n");
printf("| 2) Encrypt a message |\n");
printf("| 3) Decrypt a message) |\n");
printf("| 4) Quit) |\n");
printf("--------------------------------\n");
printf("Option: ");
scanf(" %d%c",&userchoice,&dump);
return userchoice;
}
int getShift(){
int newshift = 0;
char dump = 0;
printf("Enter a new shift value:");
scanf("%d,%c",&newshift,&dump);
return newshift;
}
void getString(char buf[]){
printf(" Input: ");
fgets(buf,SIZE,stdin);
}
void encrypt(char buf[], int shift){
int i = 0;
while(buf[i] != '\0'){
if (buf[i] == 32){
buf[i] = buf[i];
i++;
}
else if (buf[i] == 10){
buf[i] == 32;
i++;
}
else{
buf[i] -= shift;
i++;
}
}
printf("Output: %5s\n",buf);
}
void decrypt(char buf[], int shift){
int i = 0;
while(buf[i] != '\0'){
if (buf[i] == 32){
buf[i] = buf[i];
i++;
}
else if (buf[i] == 10){
buf[i] == 32;
i++;
}
else{
buf[i] += shift;
i++;
}
}
printf("Output: %5s\n",buf);
}
最佳答案
我测试了上面的代码,这些是我遇到的错误类型(VC++命令行)
error C2371: 'getString': redefinition; different basic types
将函数移至 main()
上方,因为函数应在使用前声明。
error C2065: 'SIZE': undeclared identifier
我将 SIZE
替换为 1024
进行测试。
还有警告:
warning C4553: '==': result of expression not used; did you intend '='?
对于这些
else if (buf[i] == 10){
buf[i] == 32;
i++;
}
完成、格式化和更改我用于测试的代码
#include <stdio.h>
#include <stdlib.h>
int getUserChoice()
{
int userchoice = 0;
char dump = 0;
printf("--------------------------------\n");
printf("| 1) Change Shift (Default 3) |\n");
printf("| 2) Encrypt a message |\n");
printf("| 3) Decrypt a message |\n");
printf("| 4) Quit) |\n");
printf("--------------------------------\n");
printf("Option: ");
scanf(" %d%c", &userchoice, &dump);
return userchoice;
}
int getShift()
{
int newshift = 0;
char dump = 0;
printf("Enter a new shift value:");
scanf("%d,%c", &newshift, &dump);
return newshift;
}
void getString(char buf[])
{
printf(" Input: ");
fgets(buf, 1024, stdin);
}
void encrypt(char buf[], int shift)
{
int i = 0;
while (buf[i] != '\0')
{
if (buf[i] == 32)
{
buf[i] = buf[i];
i++;
}
else if (buf[i] == 10)
{
buf[i] = 32;
i++;
}
else
{
buf[i] -= shift;
i++;
}
}
printf("Output: %5s\n", buf);
}
void decrypt(char buf[], int shift)
{
int i = 0;
while (buf[i] != '\0')
{
if (buf[i] == 32)
{
buf[i] = buf[i];
i++;
}
else if (buf[i] == 10)
{
buf[i] = 32;
i++;
}
else
{
buf[i] += shift;
i++;
}
}
printf("Output: %5s\n", buf);
}
int main()
{
int shift = 3;
char stringresponse[1024];
while (1 || 2 || 3)
{
switch (getUserChoice())
{
case 1:
shift = getShift();
break;
case 2:
getString(stringresponse);
encrypt(stringresponse, shift);
break;
case 3:
getString(stringresponse);
decrypt(stringresponse, shift);
break;
default:
printf("Exiting the program");
exit(0);
}
}
return 0;
}
关于c - 在 while 循环中使用函数(在 Atom 中有效,但在 VIM 中无效),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57931230/
我有一台计算机在一个非常严格的代理服务器后面,它只允许我上网和下载程序它不允许像 Atom 文本编辑器这样的程序下载它的包。 我的问题是如何仅使用基于浏览器的下载来安装它们? 最佳答案 这当然是可能的
我的 keymap.cson 文件中有这个: 'body': 'ctrl-alt-left': 'editor:select-to-first-character-of-line' 但是不行(没有
如何获取 Atom 中所有已安装和已激活插件的列表? 我可以用 apm list --installed --bare获取所有已安装的软件包,但我不想包含禁用的软件包。而且我有很多禁用的包。 最佳答案
我在 OSX 上,在 Atom 中打开了一个我没有命名的文件。我不得不重新启动计算机,当它再次出现时,我点击了错误的东西,它忘记了所有旧文件名,并且未命名的文件似乎消失得无影无踪。如果我使用 Time
当我搜索某个字符串(“在目录中搜索”)时,atom 允许做两件事:指定目录或文件扩展名(但它会在项目中的所有目录中搜索)。是否可以同时进行?例如。我想在 'src' 目录中进行递归搜索,但只使用 *.
我将 OSX 更新为 High Sierra,我的 Atom 停止从命令行工作。 $ atom . FSPathMakeRef(/Applications/Atom.app) failed with
下面屏幕截图中第 95 行和第 96 行之间的红色箭头在 GitHub 的 Atom 编辑器上意味着什么? 谢谢! 最佳答案 如果您当前打开的项目使用 Git 作为修订系统,装订线中的箭头表示您删除了
某些代码编辑器(例如 WebStorm)可以选择在编辑器失去焦点时自动保存。我在 Atom 编辑器中搜索了类似的选项,但尚未找到任何内容。 Atom 编辑器是否有一个设置,允许在失去焦点时自动保存已编
有没有办法(插件或其他东西)在 Atom 编辑器中使用分屏? 我查看了菜单,但找不到任何相关选项。 最佳答案 使用命令面板 使用 cmd + shift + p (OSX) 或 ctrl + 打开命令
我在 Atom 中安装了一个有缺陷的软件包,它导致编辑器反复崩溃。因此,我进入 Atom 设置将其删除,但出于好奇,我事先单击了“打开配置文件夹”按钮,这打开了一个空窗口和开发工具: Atom 随后崩
我已经使用atom.io有一段时间了并且非常喜欢它。我只缺少一件事。我以前使用过bracket和sublime,它们都有一个功能,你只需输入html就可以创建html文档的基本结构。 这只会设置 ht
我尝试在 Atom 编辑器中安装软件包,但总是失败,就像我无法连接到服务器一样。 例如,apm install split-diff 返回请求包信息失败:getaddrinfo ENOTFOUNDat
我使用的是 OSX El Capitan 和 Atom 1.2.4。而且我还安装了“tabs-to-spaces”包。 我正在尝试将编辑器设置为缩进并使制表符为 2 个空格。但我无法完成这项工作,这是
我使用的是 Atom 1.0.15。启动时,Atom 每次都会尝试打开 MTP 设备上的文件,这非常烦人。即使关闭引用 MTP 设备上的文件的选项卡后,Atom 也会尝试在下次启动时重新打开它。 修复
我在 Atom 中安装了一个有缺陷的软件包,它导致编辑器反复崩溃。因此,我进入 Atom 设置将其删除,但出于好奇,我事先单击了“打开配置文件夹”按钮,这打开了一个空窗口和开发工具: Atom 随后崩
我尝试在 Atom 编辑器中安装软件包,但总是失败,就像我无法连接到服务器一样。 例如,apm install split-diff 返回请求包信息失败:getaddrinfo ENOTFOUNDat
在 Atom 文本编辑器上,不同的文件树颜色代表什么。我的文件有 3 种不同的颜色:黑色、绿色和橙色。黑色文件无法正常运行,而绿色文件运行良好。如果有人知道颜色的具体含义,请告诉我。 最佳答案 颜色指
我正在尝试通过 Atom 进行完整搜索,寻找特定的文本。嗯,这听起来很简单,使用 Command + Shift + F ,但是,不会跟踪 node_modules ,并且不会扫描这些目录内的内容。我
以下是我在snippets.cson 文件中编写的两个片段: '.source.python': 'print statement': 'prefix': 'pr' 'body'
我试过在这里查看其他有类似问题的问题,但不幸的是我没能解决这个问题。 关于一些基本背景信息,我目前在实验室中使用 PC,并且实验室在机构的某个地方有 GPU 服务器。我正在尝试将 Atom 编辑器连接
我是一名优秀的程序员,十分优秀!