0

am working on this problem for 2 days. i just don't know how else to write it to avoid "incompatible integer to pointer conversion initializing...". i know that the problem is made by mixing ints and strings but i don't know how else to write it. i read most of the how conversing ints to chars works and all but i just don't know how else to implement the key word. if someone can help i would really appreciate it. thanks

(Code removed to comply with academic honesty)

1
 string Final = (((UI[i] - 'A') + tolower(key[a % keyl]) - 'a') % 26) + 'A';

It is an incorrect assignment:

(((UI[i] - 'A') + tolower(key[a % keyl]) - 'a') % 26) + 'A';

The above line is an integer, but string Final, expects a string, is a non-assignable expression, you must do

int Final = .....

You do not worry it's an integer because when we use printf it will become a character, if we use the appropriate conversion: You can check this by printing the following

printf("97 = %c\n", 97);

and you'll get that 97 = a.

EDIT i just don't know how else to write it to avoid "incompatible integer to pointer conversion initializing...".

That is your question, and it has been answered, now you have other problems, but your question has already been answered.

What do you expect to happen when the next loop is executed?

for (int i = 0, j = strlen(key); i < j; i ++)
        {
            if (!isalpha(key[i]))
            printf("Key needs to be all letters. Please try again.\n");
            return 1;
        }

I'll tell you, the program ends immediately

EDIT 2

the correct way is

for (int i = 0, j = strlen(key); i < j; i ++)
            {
                if (!isalpha(key[i]))
                {                 
                printf("Key needs to be all letters. Please try again.\n");
                return 1;
                }
            }
4
  • no, program terminates instantly if i try to put it as int. also if i write it all like printf("c", and than the expression) program just terminates. so there is more to figure there :S
    – Belutak
    Aug 26 '16 at 19:40
  • you can read my edit
    – MARS
    Aug 26 '16 at 20:12
  • i thought that loop goes through each character of KEY end terminates if there is non letter character. thats not how it works? what do you see it does? EDIT: wow that thing was killing my program when i tried with int instead of string. can you tell me why that loop does not work as i imagine it should? thank you
    – Belutak
    Aug 26 '16 at 20:36
  • you can read my edit 2
    – MARS
    Aug 26 '16 at 20:42

You must log in to answer this question.

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