0

I'm trying to solve Caesar but i keep getting this error:

caesar.c:37:20: error: expected expression

 s[i] = char(int(text[i]+k-97)%26+97); \\ the arrow points to the 'c' in char
#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main(int argc, string argv[])
{
    char c;
    char s[100];
    if (argc != 2)
    {
        printf("Erro:Missing key\n");
        return 1;
    }

    string key=argv[1];
    //is it a digit ?
    for(int i=0; i<strlen(key); i++)
    {
        if (!isdigit(key[i]))
        {
             printf("fail\n");
             return 1;
        }

    }
     //Get text from user
    string text=get_string("Plaintext: ");
    int k=atoi(key);
    k=k%26;
    for(int i=0; i<strlen(text); i++)
    {
        c=text[i];
        if (c>='a' && c<='z')
        {
             s[i] = char(int(c+k-97)%26+97);
        }
        else if (c>='A' && c<='Z')
        {
            s[i] = char(int(c+k-65)%26+65);
           }
    }
    printf("%s", s);

}

1 Answer 1

1

This doc shows the correct syntax for the typecast operator in C.

Syntax

( type-name ) expression

Typecasting is demonstrated in the lecture at around 1:03:00.

You must log in to answer this question.

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