#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 ('A' + (c - 'A' + ROT) % 26);;
}
}
// Execution of the whole program begins at the main function
int main(int argc, char *argv[])
{
for (int j = 2; j < argc; j++){
// Calculate the length of the second argument
int length = strlen(argv[j]);
// Loop for every character in the text
for (int i = 0; i< length; i++)
{
// Determine and print the ciphered character
printf("%c" ,rotate(argv[j][i]));
printf("%c" ,rotate(argv[j][i])-ROT);
printf("%d",i+1);
printf("\n");
}
// Print one final new-line character
printf("\n");
}
// Exit indicating success
exit(EXIT_SUCCESS);
return 0;
}
Я борюсь с программой, которая вращает заданные символы по количеству пользовательского типа в качестве первого аргумента argv.Передача аргумента от главного к функции в C
Теперь мне нужно изменить программу, чтобы достичь этого. В вопросе говорится, что я могу использовать функцию àtoi` для этого.
Мое замешательство в том, что как мое значение argv[1]
в Main быть передано в функцию rotate (Variable ROT)?
Идеальный выход будет (используя терминал в MAC)
./rot 1 ABC
AB1
BC2
CD3
Измените свой вопрос и сообщите нам, какой желаемый результат должен быть для данного входа. –
опубликованный код имеет значительную логическую ошибку, он неправильно обрабатывает что-либо, кроме ... z и A ... Z все остальные символы, пробелы, табуляция, точка с запятой и т. Д. Приведет к сбою программы. – user3629249