gpt4 book ai didi

C - 赋值从 Integer 生成指针而不进行强制转换

转载 作者:太空宇宙 更新时间:2023-11-04 08:23:52 25 4
gpt4 key购买 nike

<分区>

只是在 C 中创建一个简单的密码程序。初学者程序员但在字符串等方面遇到麻烦。无论如何,这是程序如果你能帮忙请告诉我。编译器报错如题。

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

// Compile this program with:
// cc -std=c99 -Wall -Werror -pedantic -o rot rot.c

#define ROT 3

// The rotate function returns the character ROT positions further along the
// alphabetic character sequence from c, or c if c is not lower-case

char rotate(char c)
{
// Check if c is lower-case or not
if (islower(c))
{
// The ciphered character is ROT positions beyond c,
// allowing for wrap-around
return ('a' + (c - 'a' + ROT) % 26);
}
else
{
return c;
}
}

// Execution of the whole program begins at the main function

int main(int argc, char *argv[])
{
// Exit with an error if the number of arguments (including
// the name of the executable) is not precisely 2
if(argc != 2)
{
fprintf(stderr, "%s: program expected 1 argument, but instead received %d\n", argv[0], argc-1);
exit(EXIT_FAILURE);
}
else
{
// Calculate the length of the first argument
int length = strlen(argv[1]);

//Convert every character to lowercase characters

for(int i=0 ; argv[i] ; i++){
char letternumber = 0;

argv[1][i] = letternumber;
argv[1][i] = tolower(letternumber);
}


// Loop for every character in the text
for (int i = 0; i < length; i++)
{
// Determine and print the ciphered character
printf("%c", rotate(argv[1][i]));
printf(" ");
printf("%c", argv[1][i]);
printf(" ");
printf("%d", i);
printf("\n");

}

// Print one final new-line character
printf("\n");

// Exit indicating success
exit(EXIT_SUCCESS);
}
return 0;
}

编辑:因此,我还对代码进行了一些修改。正如鲍勃所建议的那样。但是,我仍然有一个问题,前两个字母输出就消失了。请帮助解释为什么会发生这种情况,如果我的问题非常愚蠢,请原谅我。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com