c - "Incompatible integer to pointer conversion" -
the following program refusing compile because of these errors:
vigenere.c:52:31: error: incompatible integer pointer conversion assigning 'string' (aka 'char *') 'int' [-werror,-wint-conversion] ...ciphertext[i] = ((((plaintext[i] - 65) + keyword[num % keylength]) % 26) + 65); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vigenere.c:56:31: error: incompatible integer pointer conversion assigning 'string' (aka 'char *') 'int' [-werror,-wint-conversion] ...ciphertext[i] = ((((plaintext[i] - 97) + keyword[num % keylength]) % 26) + 97); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and here's program, meant implement simple vigenere cipher:
#include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> int main(int argc, string argv[]) { if(argc != 2) { printf("invalid input; try again!\n"); return 1; } else if(argv[1]) { for(int = 0, n = strlen(argv[1]); < n; i++) { if(!isalpha(argv[1][i])) { printf("invalid input; try again!\n"); return 1; } } } // plaintext user string plaintext = getstring(); string ciphertext[100]; int num = 0; string keyword = argv[1]; int keylength = strlen(keyword); // change key values letters shifts for(int = 0, n = keylength; < n; i++) { if(isupper(keyword[i])) { keyword[i] = keyword[i] - 65; } else if(islower(keyword[i])) { keyword[i] = keyword[i] - 97; } } for(int = 0, n = strlen(plaintext); < n; i++) { if(isalpha(plaintext[i])) { if(isupper(plaintext[i])) { ciphertext[i] = ((((plaintext[i] - 65) + keyword[num % keylength]) % 26) + 65); } else if(islower(plaintext[i])) { ciphertext[i] = ((((plaintext[i] - 97) + keyword[num % keylength]) % 26) + 97); } num++; } // non-alphabetic characters else { ciphertext[i] = plaintext[i]; } printf("%c", ciphertext[i]); } printf("\n"); }
i've no idea why compiler throws error, because have older version of program, compiled few months ago (the code same on lines 52 , 56) works fine.
i'll appreciate , :)
variable ciphertext
array of char*
, think should be:
char ciphertext[1000]
Comments
Post a Comment