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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -