Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 编写密码程序_C_Encryption - Fatal编程技术网

C 编写密码程序

C 编写密码程序,c,encryption,C,Encryption,编写一个程序(过滤器),从标准输入中读取ASCII流 并将字符发送到标准输出。程序将丢弃所有其他字符 而不是信件。任何小写字母都将作为大写字母输出。 以五个字符为一组输出字符,以空格分隔。输出换行符 每10组后一个字符。(行上的最后一个组后面只有换行符; 一行的最后一组后面没有空格。)最后一组可以 少于五个字符,最后一行可能少于10个组。假设输入文件是任意长度的文本文件。使用getchar()和 putchar()用于此。您永远不需要输入超过一个字符的数据 一次在记忆中 我遇到的问题是如何做间隔

编写一个程序(过滤器),从标准输入中读取ASCII流 并将字符发送到标准输出。程序将丢弃所有其他字符 而不是信件。任何小写字母都将作为大写字母输出。 以五个字符为一组输出字符,以空格分隔。输出换行符 每10组后一个字符。(行上的最后一个组后面只有换行符; 一行的最后一组后面没有空格。)最后一组可以 少于五个字符,最后一行可能少于10个组。假设输入文件是任意长度的文本文件。使用getchar()和 putchar()用于此。您永远不需要输入超过一个字符的数据 一次在记忆中

我遇到的问题是如何做间隔。我创建了一个包含5个对象的数组,但我不知道如何处理它。这就是我到目前为止所做的:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
    char c=0, block[4]; 

    while (c != EOF)
    {
       c=getchar();

       if (isupper(c))
       {
           putchar(c);
       }
       if (islower(c))
       {
          putchar(c-32);
       }
    }
 }
#包括
#包括
#包括
int main()
{
字符c=0,块[4];
而(c!=EOF)
{
c=getchar();
如果(上(c))
{
普查尔(c);
}
if(岛下(c))
{
putchar(c-32);
}
}
}

执行问题中描述的算法不需要存储字符

你应该一次读一个字符,并记录我不会透露的两个计数器。每个计数器都允许您知道在哪里放置格式化输出所需的特殊字符

基本上:

read a character
if the character is valid for output then
   convert it to uppercase if needed
   output the character
   update the counters
   output space and or newlines according to the counters
end if
希望这有帮助


另外:我不知道你试图用
block
变量做什么,但它被声明为4个元素的数组,文本中没有使用数字4…

闻起来像是家庭作业…如果你给他原样的答案,OP将永远不会学会如何创建算法。如果你要感谢我,请投票给我的答案,并接受它。( )
int main()
{
    char c=0; 
    int charCounter = 0;
    int groupCounter = 0;

    while (c != EOF)
    {
       c=getchar();

       if (isupper(c))
       {
           putchar(c);
           charCounter++;
       }
       if (islower(c))
       {
          putchar(c-32);
          charCounter++;
       }

       // Output spaces and newlines as specified.
       // Untested, I'm sure it will need some fine-tuning.
       if (charCounter == 5)
       {
           putchar(' ');
           charCounter = 0;
           groupCounter++;
       }

       if (groupCounter == 10)
       {
           putchar('\n');
           groupCounter = 0;
       }
    }
 }