Reputation:
I am new to C programming, and I am trying to figure out how to put a period in between letters. This is my code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void CreateAcronym(char userPhrase[], char userAcronym[]) {
int i;
int count = 0;
for (i = 0; i < strlen(userPhrase); ++i) {
if (i == 0 || userPhrase[i - 1] == ' ') {
if (isupper(userPhrase[i])) {
userAcronym[count++] = userPhrase[i];
}
}
}
userAcronym[count] = '\0';
}
int main() {
char userPhrase[1000];
char userAcronym[20];
fgets(userPhrase, 1000, stdin);
CreateAcronym(userPhrase, userAcronym);
printf("%s\n", userAcronym);
return 0;
}
Example Input: Institute of Electrical and Electronics Engineers
My current Output: IEEE
What the output should be: I.E.E.E.
How do I insert the periods in the printf function so it will output to I.E.E.E.?
Upvotes: 0
Views: 469
Reputation: 10880
Instead of writing userAcronym[count++] = userPhrase[i];
, you'd like to add both the character and the period:
userAcronym[count++] = userPhrase[i];
userAcronym[count++] = '.';
Upvotes: 2