0

I am making a program for pset2, caesar. At the moment 6 errors are generating, but I have no idea what any of them mean. Here is my code so far:

...
            {
                printf(((("%c", p[i] - 97)+k)%26)+97);
            }
            else
            {
                printf(((("%c", p[i] - 65)+k)%26)+65);
            }
        }
...
}
[EDIT: unrelated code removed for Honor Code compliance.]

And these are the codes that are coming up when compiling the program:

~/workspace/pset2/caesar/ $ make caesar
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    caesar.c  -lcrypt -lcs50 -lm -o caesar
caesar.c:26:27: error: expression result unused [-Werror,-Wunused-value]
                printf(((("%c", p[i] - 97)+k)%26)+97);
                          ^~~~
caesar.c:26:24: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion]
                printf(((("%c", p[i] - 97)+k)%26)+97);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdio.h:362:43: note: passing argument to parameter '__format' here
extern int printf (const char *__restrict __format, ...);
                                          ^
caesar.c:26:24: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
                printf(((("%c", p[i] - 97)+k)%26)+97);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
caesar.c:30:27: error: expression result unused [-Werror,-Wunused-value]
                printf(((("%c", p[i] - 65)+k)%26)+65);
                          ^~~~
caesar.c:30:24: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion]
                printf(((("%c", p[i] - 65)+k)%26)+65);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdio.h:362:43: note: passing argument to parameter '__format' here
extern int printf (const char *__restrict __format, ...);
                                          ^
caesar.c:30:24: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
                printf(((("%c", p[i] - 65)+k)%26)+65);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.
make: *** [caesar] Error 1

I am very much a newbie at programming, so any help would be much appreciated.

Thanks, Dan

2
  • Can you please post the error messages – MEE Feb 19 '18 at 20:02
  • He did. They're in the block that follows the code. – Cliff B Feb 19 '18 at 22:04
1

This is a case of one problem generating multiple compile errors. In this case, it's just the placement of parentheses.

            printf(((("%c", p[i] - 97)+k)%26)+97);

A printf call like this has two parts inside the outer parentheses: The 'what to print' part that includes placeholders is the first part. The second part is what to put in the placeholders.

The problem here is the first part, the "%c" is included inside the inner parentheses that define what to put inside of the placeholder. All of those opening parentheses (except the first one) should follow the first comma.

There may be other issues, but fixing the syntax by correct placement of the parentheses will cure this.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .