cs50 - Splitting strings and printing the capitalized first characers in C -
i working on code takes string containing name of , prints initials of name capitalized, whenever run code, keep getting initials printed twice, don't know how fix issue , desired output.
here code:
#include <cs50.h> #include <stdio.h> #include <string.h> #include <ctype.h> int main(void) { string name = getstring(); char* pointer; pointer = strtok(name, " "); while (pointer != null) { printf("%c", putchar(toupper(pointer[0]))); pointer = strtok (null, " "); } printf("\n"); }
when run code example: ahmed salah eldin
output:
aassee
i need :
ase
you using printf()
, putchar()
need 1 of them. when call putchar()
returns output character passed printf()
, output again.
change to
fputc(toupper(pointer[0]), stdout);
Comments
Post a Comment