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 ❯ Reading with scanf
<08.01>
/* Reading a string with scanf */
#include <stdio.h> #include <string.h> int main (void) { char city[20], city2[20]; printf ("What is the capital of Canada? "); /* the string is read with the %s placeholder */ /* do not use & or use &city[0] */ scanf ("%s", city); printf ("What is the capital of Argentina? "); scanf ("%s", city2); /* here is the report */ printf ("\nThe capital of Canada is: %s.", city); printf ("\nThe capital of Argentina is: %s.", city2); return (0); }
Hergestellt in Deutschland / Made in Germany
What is the capital of Canada? Ottawa What is the capital of Argentina? Buenos Aires The capital of Canada is: Ottawa. The capital of Argentina is: Buenos.
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland