@@ -78,7 +78,7 @@ const int BIRTHYEAR = 1980;
7878
7979``` c
8080// this is a comment
81- printf ("Hello World!"); // Can comment anywhere in file
81+ printf ("Hello World!\n "); // Can comment anywhere in file
8282
8383/* Multi-line comment, print Hello World!
8484to the screen, it's awesome * /
@@ -87,12 +87,12 @@ to the screen, it's awesome */
8787### Print text
8888
8989```c
90- printf("I am learning C.");
90+ printf("I am learning C.\n ");
9191int testInteger = 5;
92- printf("Number = %d", testInteger);
92+ printf("Number = %d\n ", testInteger);
9393
9494float f = 5.99; // floating point number
95- printf("Value = %f", f);
95+ printf("Value = %f\n ", f);
9696
9797short a = 0b1010110; // binary number
9898int b = 02713; // octal number
@@ -183,7 +183,7 @@ printf("%s", greetings);
183183```
184184
185185**NOTE**: String literals might be stored in read-only section of memory. Modifying a string literal invokes undefined
186- behavior. You can't modify it. !
186+ behavior. You can't modify it!
187187
188188`C` **does not** have a String type, use `char` type and create an `array` of characters
189189
@@ -192,18 +192,18 @@ behavior. You can't modify it.!
192192```c
193193int time = 20;
194194if (time < 18) {
195- printf("Goodbye!");
195+ printf("Goodbye!\n ");
196196} else {
197- printf("Good evening!");
197+ printf("Good evening!\n ");
198198}
199199// Output -> "Good evening!"
200200int time = 22;
201201if (time < 10) {
202- printf("Good morning!");
202+ printf("Good morning!\n ");
203203} else if (time < 20) {
204- printf("Goodbye!");
204+ printf("Goodbye!\n ");
205205} else {
206- printf("Good evening!");
206+ printf("Good evening!\n ");
207207}
208208// Output -> "Good evening!"
209209```
@@ -212,7 +212,7 @@ if (time < 10) {
212212
213213``` c
214214int age = 20 ;
215- (age > 19 ) ? printf(" Adult" ) : printf(" Teenager" );
215+ (age > 19 ) ? printf(" Adult\n " ) : printf(" Teenager\n " );
216216```
217217
218218### Switch
@@ -221,10 +221,10 @@ int age = 20;
221221int day = 4 ;
222222
223223switch (day) {
224- case 3: printf("Wednesday"); break;
225- case 4: printf("Thursday"); break;
224+ case 3: printf("Wednesday\n "); break;
225+ case 4: printf("Thursday\n "); break;
226226 default:
227- printf("Weekend!");
227+ printf("Weekend!\n ");
228228}
229229// output -> "Thursday" (day 4)
230230```
@@ -403,13 +403,13 @@ switch(day) {
403403int myNum;
404404
405405// Ask the user to enter a number
406- printf ("Please enter a number: \n ");
406+ printf ("Enter a number: ");
407407
408408// Get and save the number entered by the user
409409scanf("%d", &myNum);
410410
411411// Output the number entered by the user
412- printf("The number you entered: %d", myNum);
412+ printf("The number you entered: %d\n ", myNum);
413413```
414414
415415### User input string
@@ -418,11 +418,11 @@ printf("The number you entered: %d", myNum);
418418// create a string
419419char firstName[30];
420420// Ask the user to enter some text
421- printf("Enter your name: \n ");
421+ printf("Enter your name: ");
422422// get and save the text
423423scanf("%s", &firstName);
424424// output text
425- printf("Hello %s.", firstName);
425+ printf("Hello %s.\n ", firstName);
426426```
427427
428428### memory address
@@ -442,10 +442,10 @@ To access it, use the reference operator (`&`)
442442
443443```c
444444int myAge = 43; // an int variable
445- printf("%d", myAge); // output the value of myAge(43)
445+ printf("%d\n ", myAge); // output the value of myAge(43)
446446
447447// Output the memory address of myAge (0x7ffe5367e044)
448- printf("%p", &myAge);
448+ printf("%p\n ", &myAge);
449449```
450450
451451### pointer variable {.col-span-2}
@@ -716,12 +716,12 @@ printf("%c\n", myLetter);
716716```c
717717#include <stdio.h>
718718
719- int main() {
720- printf("File : %s\n", __FILE__);
721- printf("Date : %s\n", __DATE__);
722- printf("Time : %s\n", __TIME__);
723- printf("Line : %d\n", __LINE__);
724- printf("ANSI : %d\n", __STDC__);
719+ int main(void ) {
720+ printf("File: %s\n", __FILE__);
721+ printf("Date: %s\n", __DATE__);
722+ printf("Time: %s\n", __TIME__);
723+ printf("Line: %d\n", __LINE__);
724+ printf("ANSI: %d\n", __STDC__);
725725}
726726```
727727
@@ -764,7 +764,7 @@ When you need to convert a macro parameter to a string constant, use the string
764764```c
765765#include <stdio.h>
766766
767- #define tokenpaster(n) printf ("token " #n " = %d", token##n)
767+ #define tokenpaster(n) printf ("Token " #n " = %d\n ", token##n)
768768
769769int main(void) {
770770 int token34 = 40;
@@ -823,7 +823,7 @@ int main(void) {
823823
824824``` c
825825int main (void) {
826- printf("Hello World!");
826+ printf("Hello World!\n ");
827827
828828 return 0;
829829}
@@ -855,7 +855,7 @@ int main() {
855855}
856856
857857void myFunction () {// Function definition
858- printf ("Good evening!");
858+ printf ("Good evening!\n ");
859859}
860860```
861861
@@ -864,7 +864,7 @@ void myFunction() {// Function definition
864864``` c
865865// create function
866866void myFunction () {
867- printf ("Good evening!");
867+ printf ("Good evening!\n ");
868868}
869869
870870int main () {
@@ -918,7 +918,7 @@ int myFunction(int x) {
918918}
919919
920920int main() {
921- printf("Result: %d", myFunction(3));
921+ printf("Result: %d\n ", myFunction(3));
922922 return 0;
923923}
924924// output 8 (5 + 3)
@@ -932,10 +932,10 @@ int myFunction(int x, int y) {
932932}
933933
934934int main() {
935- printf("Result: %d", myFunction(5, 3));
935+ printf("Result: %d\n ", myFunction(5, 3));
936936 // store the result in a variable
937937 int result = myFunction(5, 3);
938- printf("Result = %d", result);
938+ printf("Result = %d\n ", result);
939939
940940 return 0;
941941}
@@ -950,7 +950,7 @@ int sum(int k);
950950
951951int main() {
952952 int result = sum(10);
953- printf("%d", result);
953+ printf("%d\n ", result);
954954
955955 return 0;
956956}
@@ -970,10 +970,10 @@ int sum(int k) {
970970#include <math.h>
971971
972972void main(void) {
973- printf("%f", sqrt(16)); // square root
974- printf("%f", ceil(1.4)); // round up (round)
975- printf("%f", floor(1.4)); // round down (round)
976- printf("%f", pow(4, 3)); // x(4) to the power of y(3)
973+ printf("%f\n ", sqrt(16)); // square root
974+ printf("%f\n ", ceil(1.4)); // round up (round)
975+ printf("%f\n ", floor(1.4)); // round down (round)
976+ printf("%f\n ", pow(4, 3)); // x(4) to the power of y(3)
977977}
978978```
979979
@@ -1028,13 +1028,13 @@ int main() {
10281028 struct myStructure s1;
10291029 strcpy(s1. myString, "Some text");
10301030 // print value
1031- printf("my string: %s", s1.myString);
1031+ printf("My string: %s\n ", s1.myString);
10321032
10331033 return 0;
10341034}
10351035```
10361036
1037- Assigning values to strings using the ` strcpy ` function
1037+ Assigning values to strings using the ` strcpy ` function
10381038
10391039### Accessing structure members {.row-span-2}
10401040
@@ -1100,7 +1100,7 @@ struct myStructure s1 = {
11001100s1.myNum = 30;
11011101s1.myLetter = 'C';
11021102// print value
1103- printf("%d %c %s ",
1103+ printf("%d %c",
11041104 s1.myNum,
11051105 s1.myLetter);
11061106```
0 commit comments