C/Console/Console Output String
Содержание
A simple example for printf
#include <stdio.h>
int main(void)
{
printf("This is an example of redirection.\n");
return 0;
}
Displaying a Quotation: the main function
/*Displaying a Quotation */
#include <stdio.h> /* stdio.h is a preprocessor directive */
void main() /* void main() identifes the function main()
The entry point of the program.
*/
{ /* "{" marks the beginning of main() */
printf("Hi!"); /* This line displays a String */
} /* "}" marks the end of main() */
Displaying a string
#include <stdio.h>
void main()
{
printf("The character \0 is used to terminate a string");
}
Output a string to stdout: how to use puts
#include <stdio.h>
int main ()
{
char string [] = "Hiiiiiiiiiiii!";
puts (string);
}
Output string to console
#include <stdio.h>
int main(void)
{
puts("one");
puts("two");
puts("three");
return 0;
}
prints Hello on standard output
#include <stdio.h>
main() {
printf("Hello \n");
}
Print the string in the reverse order
#include <string.h>
#include <stdio.h>
void pr_reverse(char *s);
int main(void)
{
pr_reverse("I like C");
return 0;
}
void pr_reverse(char *s)
{
register int i;
for(i = strlen(s) - 1; i >= 0; i--)
putchar( s [ i ] );
}
Read and output string
#include <stdio.h>
int main(void)
{
char str[80];
printf("Enter a string: ");
scanf("%s", str);
printf("Here"s your string: %s", str);
return 0;
}