0

code will not space my sentences

hey, my code works but when I type in a sentence there aren't any spaces between. can someone tell me what I need to do to fix it? Thank you! #include <cs50.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(int argc, string argv[]) { if (argc != 2) { printf("Usage: ./caesar key\n"); return 1; } int k = atoi(argv[1]); do { string p = get_string("plaintext: "); for (int i = 0, n = strlen(p); i < n; i++) { if (islower(p[i])) { printf("%c", (((p[i] + k) - 97) % 26) + 97); } else if (isupper(p[i])) { printf("%c", (((p[i] + k) - 65) % 26) + 65); } } printf("\n"); return 1; } while (argc == 2); }

3rd Sep 2019, 6:52 PM
David
David - avatar
2 Respuestas
+ 1
Assuming get_string supports space separated strings. Just add another else if that tests if p[i] is a space and then print a space? https://en.cppreference.com/w/c/string/byte/isspace
3rd Sep 2019, 7:30 PM
Dennis
Dennis - avatar
0
Dennis it worked! thanks a lot man. Appreciate it.
3rd Sep 2019, 7:43 PM
David
David - avatar