【发布时间】:2016-11-23 14:34:29
【问题描述】:
这是我的代码。 C 中的替换密码。但我在这一行遇到错误:char *encryption (char cipher_text[]) { 此处不允许函数定义。我想可能是“主要”功能的地方不对。我该如何解决?
顺便说一句,我怎样才能为这段代码生成随机字母?非常感谢。
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <string.h>
char *encryption (char cipher_text[]) {
int i, val, j;
printf("\n abcdefghijklmnopqrstuvwxyz \n");
【问题讨论】:
-
你不能嵌套函数..
-
如果你想生成一个随机字母表,看看使用
rand()函数 - 你想生成一个随机数并将其修改为 26,然后添加 97,并存储变量在char。请参阅 asciitable.com/index/asciifull.gif 了解我们添加 97 的原因 -
srand((unsigned int) time(NULL) ); char key = rand( ) % 26 + 'a';我为随机生成字母添加了这一行,但出现错误:cipher_text[i]=key[j];下标值不是数组、指针或向量。我该如何解决?
标签: c encryption