我不太明白这些错误来自哪里。我正在尝试创建一个简单的 C 程序,它接受一个字符串并向 ASCII 值添加一个偏移量,以创建一个极其简单的加密。
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
char obscufate_char(char origchar, int offset){
if(strcmp(origchar, " ") != 0){
int temp = origchar;
char newChar = temp + 4;
return newChar;
}
else{
return 20;
}
}
int main(int argc, string argv[]){
if(argv[1] != NULL){
string message = argv[1];
}else{
printf("%s\n", "Enter a string to encrypt\n");
string message = GetString();
}
if(argv[2] != NULL){
int offset = atoi(argv[2]);
}else{
printf("%s\n", "Enter a offset\n");
int offset = GetInt();
}
printf("%s%s\n", "Your original text is: ", message);
printf("%s\n", "Your new message is: ");
for(int i = 0; i < strlen(message); i++){
printf("%c\n", obscufate_char(message[i]),offset);
}
return 0;
}
simple_crypt.c:7:12: error: incompatible integer to pointer conversion passing
'char' to parameter of type 'const char *'; take the address with &
[-Werror]
if(strcmp(origchar, " ") != 0){
^~~~~~~~
&
/usr/include/string.h:143:34: note: passing argument to parameter '__s1' here
extern int strcmp (__const char *__s1, __const char *__s2)
^
simple_crypt.c:20:10: error: unused variable 'message'
[-Werror,-Wunused-variable]
string message = argv[1];
^
simple_crypt.c:23:10: error: unused variable 'message'
[-Werror,-Wunused-variable]
string message = GetString();
^
simple_crypt.c:27:7: error: unused variable 'offset' [-Werror,-Wunused-variable]
int offset = atoi(argv[2]);
^
simple_crypt.c:30:7: error: unused variable 'offset' [-Werror,-Wunused-variable]
int offset = GetInt();
^
simple_crypt.c:33:46: error: use of undeclared identifier 'message'
printf("%s%s\n", "Your original text is: ", message);
^
simple_crypt.c:35:28: error: use of undeclared identifier 'message'
for(int i = 0; i < strlen(message); i++){
^
simple_crypt.c:36:33: error: use of undeclared identifier 'message'
printf("%c\n", obscufate_char(message[i]),offset);