Reputation: 43
I'm trying to encrypt my string so I have a simple code where I need to modify the string by accessing its indices and modify each character in the string. I was running it as a normal file with gcc command at first and it worked but when I try to include it in my C file with MPI then it gives me error.
The expected result will be if the string input is "Hello" then the output will be "Khoor".
char str[10] = "Hello";
for(int i = 0; i < strlen(str); i++)
str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value
printf("\nEncrypted string: %c\n", str);
The error:
error: subscripted value is not an array, pointer, or vector str[i] = str[i] + 3; //the key for encryption is 3 that i...
Upvotes: 0
Views: 89
Reputation: 51915
Your problem is trivial and the solution is simple! When you want to print a string (character array) with printf
use the %s
format specifier; the %c
format is for a single character! So, try this:
printf("\nEncrypted string: %s\n", str);
Upvotes: 1