Printing strings and characters using printf() C function
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info: none
To do: Printing strings and characters using printf() C function
To show: How to print character and string using C printf() function
// Printing strings and characters
#include <stdio.h>
int main(void)
{
char character = 'A';
// Using unsized array variable
char string[] = "This is a string";
// Using pointer variable
char *stringPtr = "This is also a string";
printf("---------------------------------\n");
printf("---Character and String format---\n");
printf("---------------------------------\n\n");
printf("%c <--This one is character\n", character);
printf("\nLateral string\n");
printf("%s\n", "This is a string");
printf("\nUsing array name, the pointer to the first array's element\n");
printf("%s\n", string);
printf("\nUsing pointer, pointing to the first character of string\n");
printf("%s\n", stringPtr);
return 0;
}
Output example:
---------------------------------
---Character and String format---
---------------------------------
A <--This one is character
Lateral string
This is a string
Using array name, the pointer to the first array's element
This is a string
Using pointer, pointing to the first character of string
This is also a string
Press any key to continue . . .