C++gets_s老是不过求助大佬 - 爱问答

(爱问答)

C++gets_s老是不过求助大佬


#include <stdio.h>

#include <string.h>

#include <bits/stdc++.h>

#define _CRT_SECURE_NO_WARNINGS

#define _CRT_SECURE_NO_DEPRECATE

#pragma warning(disable:4996);

//首先将摩斯电码的36个符号及其电码(1对应.,0对应-)记录在一个数组内

char a[36][6] = { "10","0111","0101","011","1","1101","001","1111","11","1000","010","1011","00","01","000","1001","0010","101","111","0","110","1110","100","0110","0100","0011","00000","10000","11000","11100","11110","11111","01111","00111","00011","00001" };

//此函数实现摩斯电码的查找比对功能

void search(char s[6])

{

for (int i = 0; i < 36; i++)

if (strcmp(s, a[i]) == 0)

{

if (i < 26)

putchar(i + 97);

else 

putchar(i + 48 - 26);

break;

}

for (int i = 0; i < 6; i++)

s[i] = 0;

}

//这是主要的函数 主要是实现莫尔斯电码的翻译过程

void translate(char *s)

{

char dest[6];

int index = 0;

for (int i = 0; s[i] != ''; i++)

{

if (s[i] == ' ' || s[i] == '/')  

{

dest[index] = '';

search(dest);

index = 0;

}

else

{

dest[index++] = s[i];

}

}

dest[index] = 0;

search(dest);

} //待翻译的电码需要以空格和除号分隔开来 

int main()

{

printf("请输入莫尔斯电码或明文:");

char *s;

s = new char[10000];

gets_s(s,10000);

if (s[0] != '.'&&s[0] != '-') 

{ //如果要将正常的字符翻译成摩斯电码,直接输入字符串即可,如果要将摩斯电码翻译成字符串 直接输入摩斯电码即可

//程序有自动识别的功能

for (int i = 0; i < strlen(s); i++)

if (s[i] >= '0' && s[i] <= '9')

printf(a[26 + s[i] - 48]);

else 

if (s[i] >= 'a'&& s[i] <= 'z')

printf(a[s[i] - 97]);

else

if (s[i] >= 'A' && s[i] <= 'Z')

printf(a[s[i] - 65]);

else 

{

printf("?");

break;

}

}

else 

{

for (int i = 0; s[i] != ''; i++)

if (s[i] == '.')

s[i] = '1';

else 

if (s[i] == '-')

s[i] = '0';

translate(s);

}

return 0;

}//5016C:UsersAdministratorDesktop未命名2.cpp[Error] 'gets_s' was not declared in //this scope


你程序中的'gets_s' ,是非标准的C++函数,只有VS2013以上的vc++才有的,对其它编译器,你直接用gets就可以了

下一篇:appstore问题

上一篇:能给我解释一下c语言程序问题吗?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?