So I'm working on pset2's Caesar and wanted decided it would be better to put the algorithm into functions, with each function operating based on whether a character is uppercase or lowercase. Now that I'm trying to integrate those functions into the main function, I get

error: expression result unused [-Werror,-Wunused-value]

For each function. Maybe I'm just making this more complicated than I need to, or maybe I'm going in a totally wrong direction, but these are the last two errors I have to clear. Here's my code:

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

void lowercase(char character);
void uppercase(char character);
int big_letters = 65;
int small_letters = 97;
//int key = argv[1];
int enciph_Len;
string encipher;
//void lowercase(int n);
int key;

int main(int argc, string argv[ ])

    if (argc != 2)
        return 1;

    printf("Enter message you want enciphered:\n");
    encipher = get_string();
    enciph_Len = strlen(encipher);

    key = atoi(argv[1]);

    for (int i = 0; i < enciph_Len; i++){

        if (isalpha(encipher[i]) ){
            } else if (islower(encipher[i])){

            printf("%c", encipher[i]);
        } else {

    printf("%i\n", key);


void uppercase(char character){
        (character+key) % 26 + big_letters;

void lowercase(char character){
        (character+key) % 26 + small_letters;


Then I get this after trying to make/compile 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:59:30: error: expression result unused [-Werror,-Wunused-value]
            (character+key) % 26 + big_letters;
            ~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
caesar.c:63:30: error: expression result unused [-Werror,-Wunused-value]
         (character+key) % 26 + small_letters;
         ~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~

2 errors generated. make: *** [caesar] Error 1

Thanks for any help!


It's exactly what it says. You have written an expression:

(character+key) % 26 + big_letters;

but you aren't setting the results of that expression to anything, hence it is unused.

You're doing the equivalent of saying

3 + 6

I'm guessing you actually want that function to calculate a new value and return it to main? If that's the case, then it can't be a void function, but should return the value you are calculating.

  • Ah, got you! Declaring functions (and writing them out) in C is pretty confusing when you're coming from other languages... – DeltaFlyer Dec 3 '17 at 23:08

You must log in to answer this question.

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