IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CStrings : Transformation
<08.05>
/* Manipulating strings */
#include <stdio.h> #include <string.h> #include <ctype.h> /* This function takes a string and returns another all in uppercase letters */ void uppercase (char in[], char out[]) { int i; /* transforms letters in uppercase one by one */ for (i=0; i<=strlen(in); ++i) out[i] = toupper(in[i]); } /* This function takes a string and returns another with only the letters */ void onlyletters (char in[], char out[]) { int i, j; /* j is the counter for the new string */ j=0; for (i=0; i<=strlen(in); ++i) { /* sends char to new string only if letter */ /* must send also the end-of-string character */ if (isalpha(in[i]) || in[i]=='\0') { out[j] = in[i]; j=j+1; } } } int main (void) { char before[50], after[50]; printf ("Enter a phrase: "); fgets (before, 50, stdin); before[strlen(before)-1] = '\0'; printf ("Original sentence: %s.\n", before); uppercase (before, after); printf ("In uppercase: %s.\n", after); onlyletters (before, after); printf ("Only the letters: %s.\n", after); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter a phrase: Monday, March 14, 2005 Original sentence: Monday, March 14, 2005. In uppercase: MONDAY, MARCH 14, 2005. Only the letters: MondayMarch.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland