├── .gitattributes
├── .gitignore
├── 01_Calc
├── 01_Calc.vcxproj
└── main.c
├── 02_Calc
├── 02_Calc.vcxproj
├── 02_Calc.vcxproj.filters
└── main.c
├── 03_Calc
├── 03_Calc.vcxproj
├── 03_Calc.vcxproj.filters
└── main.c
├── Arrays
├── Arrays.vcxproj
├── Arrays.vcxproj.filters
└── main.c
├── BlockScope
├── BlockScope.vcxproj
├── BlockScope.vcxproj.filters
└── main.c
├── BreakAndContinue
├── BreakAndContinue.vcxproj
├── BreakAndContinue.vcxproj.filters
└── main.c
├── CDdatabase
├── CDdatabase.vcxproj
├── CDdatabase.vcxproj.filters
├── cd_database.bin
├── cddb.c
├── cddb.h
├── main.c
├── mystring.c
└── mystring.h
├── CProjects.props
├── CProjects.sln
├── CharFunctions
├── CharFunctions.vcxproj
├── CharFunctions.vcxproj.filters
└── main.c
├── Enums
├── Enums.vcxproj
├── Enums.vcxproj.filters
└── main.c
├── FileBasics
├── FileBasics.vcxproj
├── FileBasics.vcxproj.filters
├── main.c
└── test.txt
├── FileSearchStr
├── FileSearchStr.vcxproj
├── FileSearchStr.vcxproj.filters
├── main.c
└── sonnet.txt
├── FileStats
├── FileStats.vcxproj
├── FileStats.vcxproj.filters
├── empty.txt
├── main.c
└── sonnet.txt
├── Functions
├── Functions.vcxproj
├── Functions.vcxproj.filters
└── main.c
├── GetInput
├── GetInput.vcxproj
├── GetInput.vcxproj.filters
└── main.c
├── HeaderFiles
├── HeaderFiles.vcxproj
├── HeaderFiles.vcxproj.filters
├── main.c
├── mystring.c
└── mystring.h
├── HelloWorld
├── HelloWorld.vcxproj
├── HelloWorld.vcxproj.filters
└── main.c
├── HelloWorldAgain
├── HelloWorldAgain.vcxproj
├── HelloWorldAgain.vcxproj.filters
└── main.c
├── HelloWorldArgs
├── HelloWorldArgs.vcxproj
├── HelloWorldArgs.vcxproj.filters
└── main.c
├── LogicalOperators
├── LogicalOperators.vcxproj
├── LogicalOperators.vcxproj.filters
└── main.c
├── MultiDimensionArrays
├── MultiDimensionArrays.vcxproj
├── MultiDimensionArrays.vcxproj.filters
└── main.c
├── NamingConventions
├── NamingConventions.vcxproj
├── NamingConventions.vcxproj.filters
└── main.c
├── Operators
├── Operators.vcxproj
├── Operators.vcxproj.filters
└── main.c
├── Printf
├── Printf.vcxproj
├── Printf.vcxproj.filters
└── main.c
├── README.md
├── ReadFile
├── ReadFile.vcxproj
├── ReadFile.vcxproj.filters
├── main.c
└── sonnet.txt
├── ReadLine
├── ReadLine.vcxproj
├── ReadLine.vcxproj.filters
└── main.c
├── ReturnStrings
├── ReturnStrings.vcxproj
├── ReturnStrings.vcxproj.filters
└── main.c
├── Scope
├── Scope.vcxproj
├── Scope.vcxproj.filters
├── main.c
├── mystring.c
├── mystring.h
└── mystringutils.c
├── StringFunctions
├── StringFunctions.vcxproj
├── StringFunctions.vcxproj.filters
└── main.c
├── StringIndex
├── StringIndex.vcxproj
├── StringIndex.vcxproj.filters
└── main.c
├── StringsAndAddresses
├── StringsAndAddresses.vcxproj
├── StringsAndAddresses.vcxproj.filters
└── main.c
├── StringsAndPointers
├── StringsAndPointers.vcxproj
├── StringsAndPointers.vcxproj.filters
└── main.c
├── Structs
├── Structs.vcxproj
├── Structs.vcxproj.filters
└── main.c
├── SwitchBug
├── SwitchBug.vcxproj
├── SwitchBug.vcxproj.filters
└── main.c
├── SwitchCase
├── SwitchCase.vcxproj
├── SwitchCase.vcxproj.filters
└── main.c
├── TestAge1
├── TestAge1.vcxproj
├── TestAge1.vcxproj.filters
└── main.c
├── TestAge2
├── TestAge2.vcxproj
├── TestAge2.vcxproj.filters
└── main.c
├── Typedefs
├── Typedefs.vcxproj
├── Typedefs.vcxproj.filters
└── main.c
├── WhileLoops
├── WhileLoops.vcxproj
├── WhileLoops.vcxproj.filters
└── main.c
└── copyright.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/01_Calc/01_Calc.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {C16D7BF4-8F90-4BF0-B643-A72EC16E446B}
16 | Calc
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/01_Calc/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | int subtotal;
5 | int tax;
6 | int grandtotal;
7 | double taxrate;
8 |
9 | taxrate = 0.175;
10 | subtotal = 250;
11 | tax = subtotal * taxrate; // this should produce a warning message about possible data loss
12 | grandtotal = subtotal + tax;
13 |
14 | printf("The tax on %d is %d, so the grand total is %d.\n", subtotal, tax, grandtotal);
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/02_Calc/02_Calc.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {CE41D7FC-1671-4419-ADAE-C7A808654BE0}
16 | My02Calc
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/02_Calc/02_Calc.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/02_Calc/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | double subtotal;
5 | double tax;
6 | double grandtotal;
7 | double taxrate;
8 |
9 | taxrate = 0.175;
10 | subtotal = 250;
11 | tax = subtotal * taxrate;
12 | grandtotal = subtotal + tax;
13 |
14 | printf("The tax on %.2f is %.2f, so the grand total is %.2f.\n", subtotal, tax, grandtotal);
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/03_Calc/03_Calc.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {3DA853FE-681C-44D7-824B-BA0AD82AF873}
16 | My03Calc
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/03_Calc/03_Calc.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/03_Calc/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | #define TAXRATE_DEFINED 0.175
5 | const double TAXRATE_CONST = 0.175;
6 |
7 | double subtotal;
8 | double tax;
9 | double grandtotal;
10 | double taxrate;
11 |
12 |
13 | taxrate = 0.175;
14 | subtotal = 200;
15 | taxrate = 0.2; // redefine a variable
16 | tax = subtotal * taxrate;
17 | grandtotal = subtotal + tax;
18 |
19 | printf("(taxrate is %.3f) The tax on %.2f is %.2f, so the grand total is %.2f.\n", taxrate, subtotal, tax, grandtotal);
20 |
21 | subtotal = 200;
22 | #define TAXRATE_DEFINED 0.2 // redefine a #define 'constant' - this should produce a warning message
23 | tax = subtotal * TAXRATE_DEFINED;
24 | grandtotal = subtotal + tax;
25 |
26 | printf("(TAXRATE_DEFINED is %.3f) The tax on %.2f is %.2f, so the grand total is %.2f.\n", TAXRATE_DEFINED, subtotal, tax, grandtotal);
27 |
28 |
29 | subtotal = 200;
30 | // TAXRATE_CONST = 0.2; // cannot redefine a true constant!
31 | tax = subtotal * TAXRATE_CONST;
32 | grandtotal = subtotal + tax;
33 |
34 | printf("(TAXRATE_CONST is %.3f) The tax on %.2f is %.2f, so the grand total is %.2f.\n", TAXRATE_CONST, subtotal, tax, grandtotal);
35 |
36 | return 0;
37 | }
--------------------------------------------------------------------------------
/Arrays/Arrays.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 15.0
21 | {02CA7819-D942-42A7-9B25-A8E376F51091}
22 | Arrays
23 | 10.0.17763.0
24 |
25 |
26 |
27 | Application
28 | true
29 | v141
30 | MultiByte
31 |
32 |
33 | Application
34 | false
35 | v141
36 | true
37 | MultiByte
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | Level3
57 | Disabled
58 | true
59 | true
60 |
61 |
62 |
63 |
64 | Level3
65 | MaxSpeed
66 | true
67 | true
68 | true
69 | true
70 |
71 |
72 | true
73 | true
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Arrays/Arrays.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Arrays/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int intarray[] = { 1,2,3,4,5 };
4 | /*
5 | double doublearray2[] = {2.1, 2.3, 2.4, 2.5};
6 | char chararray[] = {'h', 'e', 'l', 'l', 'o', '\0' };
7 | char chararray2[] = "world";
8 | * */
9 |
10 |
11 | int main(int argc, char **argv) {
12 | int i;
13 |
14 | for (i = 0; i < 5; i++) {
15 | intarray[i] = (i + 1) * 100; // note use of parentheses here!
16 | }
17 |
18 | printf("--- for loop ---\n");
19 | for (i = 0; i < 5; i++) {
20 | printf("%d\n", intarray[i]);
21 | }
22 |
23 | printf("--- while loop (i = 0) ---\n");
24 | i = 0;
25 | while (i < 5) {
26 | printf("%d\n", intarray[i]);
27 | i++;
28 | }
29 |
30 | printf("--- do...while loop (i = 0) ---\n");
31 | i = 0;
32 | do {
33 | printf("%d\n", intarray[i]);
34 | i++;
35 | } while (i < 5);
36 |
37 | printf("--- while loop (i = 5) ---\n");
38 | i = 5;
39 | while (i < 5) {
40 | printf("%d\n", intarray[i]);
41 | i++;
42 | }
43 |
44 | printf("--- do...while loop (i = 5) ---\n");
45 | i = 5;
46 | do {
47 | printf("%d\n", intarray[i]);
48 | i++;
49 | } while (i < 10);
50 | /*
51 | printf("%s", chararray);
52 | printf(" %s", chararray2); */
53 | return 0;
54 | }
--------------------------------------------------------------------------------
/BlockScope/BlockScope.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {48479AEC-C50F-450A-8072-2E6760489779}
16 | BlockScope
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/BlockScope/BlockScope.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/BlockScope/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void test() {
4 | {
5 | int i = 0;
6 | printf("%d\n", i);
7 | }
8 | // printf("%d\n", i); // <----- error
9 | for (int i = 0; i < 10; i++) {
10 | printf("%d\n", i);
11 | }
12 | // printf("%d\n", i); // <----- error
13 | }
14 |
15 | int main(int argc, char **argv) {
16 | test();
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/BreakAndContinue/BreakAndContinue.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {758B07E0-564A-4AF4-BD7B-59576703D729}
16 | BreakAndContinue
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/BreakAndContinue/BreakAndContinue.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/BreakAndContinue/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char chararray[] = "Hello world! Goodbye";
4 |
5 | void whilebreak() {
6 | int i;
7 | char c;
8 | char str[50];
9 |
10 | i = 0;
11 | while (i >= 0) {
12 | c = chararray[i];
13 | printf("[%d]='%c' ", i, c);
14 | if (c == '!') {
15 | str[i] = '\0';
16 | break;
17 | }
18 | str[i] = c;
19 | i++;
20 | }
21 | printf("\nAfter while loop, str='%s'", str);
22 | }
23 |
24 | void forbreak() {
25 | int i;
26 | char str[50];
27 | char c;
28 |
29 | // for loop #1 - encrypt string
30 | for (i = 0; i < 50; i++) {
31 | c = chararray[i];
32 | if (c == ' ') {
33 | str[i] = c;
34 | continue;
35 | }
36 | if (c == '!') {
37 | str[i] = '\0';
38 | break;
39 | }
40 | str[i] = chararray[i] + 1;
41 | }
42 | printf("Encrypted string is '%s'\n", str);
43 |
44 | // for loop #2 - decrypt string
45 | for (i = 0; i < 50; i++) {
46 | c = str[i];
47 | if (c == ' ') {
48 | continue;
49 | }
50 | if (c == '\0') {
51 | break;
52 | }
53 |
54 | str[i] = str[i] - 1;
55 | }
56 | printf("Decrypted string is '%s'\n", str);
57 | }
58 |
59 | int main(int argc, char **argv) {
60 | forbreak();
61 | whilebreak();
62 | return 0;
63 | }
--------------------------------------------------------------------------------
/CDdatabase/CDdatabase.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 |
--------------------------------------------------------------------------------
/CDdatabase/cd_database.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/C-Projects/2af7e4ae1838a0b36d3c267198d1fab702d2ee0d/CDdatabase/cd_database.bin
--------------------------------------------------------------------------------
/CDdatabase/cddb.h:
--------------------------------------------------------------------------------
1 | enum score {
2 | Terrible = 1, Bad = 2, Average = 3, Good = 4, Excellent = 5
3 | };
4 |
5 | typedef char Str50[50];
6 |
7 | typedef struct cd {
8 | Str50 name;
9 | Str50 artist;
10 | int trackcount;
11 | int rating;
12 | } CD;
13 |
14 | CD *cd_collection;
15 | CD tempcd;
16 |
17 | void create_cdcollection();
18 | void display_cdcollection();
19 | int number_of_records_in_db(char*);
20 | void save_cdcollection(char*);
21 | int cdarraylen;
22 | void add_cd(char*);
23 | void modify_cd(char*);
24 |
--------------------------------------------------------------------------------
/CDdatabase/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mystring.h"
3 | #include "cddb.h"
4 |
5 | #define CDFILENAME "cd_database.bin"
6 | #define CDBACKUPFILENAME "cd_database.bak"
7 |
8 | char getcommand() {
9 | char command[MAXSTRLEN];
10 | int commandlen;
11 | char c;
12 |
13 | commandlen = readln(command);
14 | if (commandlen != 1) {
15 | c = 'x';
16 | } else {
17 | c = command[0];
18 | }
19 | return c;
20 | }
21 |
22 | int main(int argc, char **argv) {
23 | int keepgoing = 1;
24 |
25 | create_cdcollection();
26 | while (keepgoing) {
27 | printf("\nEnter a command or 'q' to quit.");
28 | printf("\nCommands: 'a'=add record, 'd'=display records, 'm'=modify record");
29 | printf("\n 'n'=number of records, 's'=save backup (from memory)\n> ");
30 | switch (getcommand()) {
31 | case 'a':
32 | printf("Add record\n");
33 | add_cd(CDFILENAME);
34 | break;
35 | case 'd':
36 | printf("Display records\n");
37 | display_cdcollection(CDFILENAME);
38 | break;
39 | case 'm':
40 | printf("Modify record\n");
41 | modify_cd(CDFILENAME);
42 | break;
43 | case 'n':
44 | printf("Number of records\n");
45 | printf("Database contains %d records\n", number_of_records_in_db(CDFILENAME));
46 | break;
47 | case 's':
48 | printf("Save backup\n");
49 | save_cdcollection(CDBACKUPFILENAME);
50 | break;
51 | case 'q':
52 | printf("Ending...\n");
53 | keepgoing = 0;
54 | break;
55 | default:
56 | printf("Invalid command.\n");
57 | break;
58 | }
59 | }
60 | return 0;
61 | }
--------------------------------------------------------------------------------
/CDdatabase/mystring.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "mystring.h"
4 |
5 | // reads line from input and returns length of string
6 | int readln(char s[]) {
7 | char ch;
8 | int i;
9 | int chars_remain;
10 |
11 | i = 0;
12 | chars_remain = 1;
13 | while (chars_remain) {
14 | ch = getchar();
15 | if ((ch == '\n') || (ch == EOF)) {
16 | chars_remain = 0;
17 | } else if (i < MAXSTRLEN - 1) {
18 | s[i] = ch;
19 | i++;
20 | }
21 | }
22 | s[i] = '\0';
23 | return i;
24 | }
25 |
26 | // returns index (0-based) of first char of searchstring in sourcestring
27 | // or -1 if searchstring is not found
28 | int searchstring(char searchstr[], char sourcestr[]) {
29 | char *ptrtostr;
30 | int foundat;
31 |
32 | foundat = -1;
33 | ptrtostr = strstr(sourcestr, searchstr);
34 | if (ptrtostr != NULL) {
35 | foundat = (int)((ptrtostr - sourcestr));
36 | }
37 | return foundat;
38 | }
--------------------------------------------------------------------------------
/CDdatabase/mystring.h:
--------------------------------------------------------------------------------
1 | #define MAXSTRLEN 200
2 | int readln(char[]);
3 | int searchstring(char[], char[]);
--------------------------------------------------------------------------------
/CProjects.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | $(SolutionDir)Build\$(Configuration)\
7 | $(SolutionDir)IntDir\$(ProjectName)\$(Configuration)\
8 |
9 |
10 |
11 | _CRT_SECURE_NO_WARNINGS%(PreprocessorDefinitions)
12 | 4477;4996
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/CharFunctions/CharFunctions.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {9313C0FC-CD23-4F96-A5A3-0C3BD1EADED6}
16 | CharFunctions
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/CharFunctions/CharFunctions.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/CharFunctions/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | char mystring[] = "On the 2nd day of Christmas my true love gave to me, 2 turtle doves and a partridge in a pear tree.";
6 |
7 | void chartypes() {
8 | int i;
9 | char c;
10 | int numDigits = 0;
11 | int numLetters = 0;
12 | int numUpCase = 0;
13 | int numLowCase = 0;
14 | int numSpaces = 0;
15 | int numPunct = 0;
16 | int numCtrl = 0;
17 | int numUnknown = 0;
18 | int lengthOfStr;
19 |
20 | lengthOfStr = strlen(mystring);
21 |
22 | for (i = 0; i < lengthOfStr; i++) {
23 | c = mystring[i];
24 | if (isalpha(c)) {
25 | numLetters++;
26 | if (isupper(c)) {
27 | printf("'%c' [uppercase character]\n", c);
28 | numUpCase++;
29 | } else {
30 | printf("'%c' [lowercase character]\n", c);
31 | numLowCase++;
32 | }
33 | } else if (isdigit(c)) {
34 | printf("'%c' [digit]\n", c);
35 | numDigits++;
36 | } else if (ispunct(c)) {
37 | printf("'%c' [punctuation]\n", c);
38 | numPunct++;
39 | } else if (isblank(c)) {
40 | printf("'%c' [blank]\n", c);
41 | numSpaces++;
42 | } else if (iscntrl(c)) {
43 | printf("'%c' [ctrl]\n", c);
44 | numCtrl++;
45 | } else {
46 | printf("'%c' [unknown]\n", c);
47 | numUnknown++;
48 | }
49 | }
50 | printf("This string contains %d characters: %d letters (%d uppercase, %d lowercase)\n", lengthOfStr, numLetters, numUpCase, numLowCase);
51 | printf("%d digits, %d ctrl, %d punctuation characters, %d spaces and %d unclassified characters.\n", numDigits, numCtrl, numPunct, numSpaces, numUnknown);
52 | }
53 |
54 | int main(int argc, char **argv) {
55 | if (isalpha('x')) { // try delimiting x as a string instead of a char: "x"
56 | printf("'x' is a letter\n");
57 | } else {
58 | printf("'x' is not a letter\n");
59 | }
60 | chartypes();
61 | return 0;
62 | }
--------------------------------------------------------------------------------
/Enums/Enums.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {2F0F1BD9-51D4-4841-A2F4-203DAEA0B7BA}
16 | Enums
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Enums/Enums.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Enums/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define NUMBER_OF_CDS 4
5 |
6 | enum score {
7 | Terrible, Bad, Average, Good, Excellent
8 | };
9 |
10 | typedef char Str50[50];
11 |
12 | typedef struct cd {
13 | Str50 name;
14 | Str50 artist;
15 | int trackcount;
16 | enum score rating;
17 | } CD;
18 |
19 | CD cd_collection[NUMBER_OF_CDS];
20 |
21 | void create_cdcollection() {
22 | strcpy(cd_collection[0].name, "Great Hits");
23 | strcpy(cd_collection[0].artist, "Polly Darton");
24 | cd_collection[0].trackcount = 20;
25 | cd_collection[0].rating = Excellent;
26 |
27 | strcpy(cd_collection[1].name, "Mega Songs");
28 | strcpy(cd_collection[1].artist, "Lady Googoo");
29 | cd_collection[1].trackcount = 18;
30 | cd_collection[1].rating = Good;
31 |
32 | strcpy(cd_collection[2].name, "The Best Ones");
33 | strcpy(cd_collection[2].artist, "The Warthogs");
34 | cd_collection[2].trackcount = 24;
35 | cd_collection[2].rating = Average;
36 |
37 | strcpy(cd_collection[3].name, "Songs From The Shows");
38 | strcpy(cd_collection[3].artist, "The Singing Swingers");
39 | cd_collection[3].trackcount = 22;
40 | cd_collection[3].rating = Excellent; // try assigning 10. Take care: your compiler may allow this!
41 | }
42 |
43 | void display_cdcollection() {
44 | int i;
45 | CD thiscd;
46 | for (i = 0; i < NUMBER_OF_CDS; i++) {
47 | thiscd = cd_collection[i];
48 | printf("CD #%d: '%s' by %s has %d tracks. My rating = %d\n", i, thiscd.name, thiscd.artist, thiscd.trackcount, thiscd.rating);
49 | }
50 | }
51 |
52 | int main(int argc, char **argv) {
53 | create_cdcollection();
54 | display_cdcollection();
55 | return 0;
56 | }
--------------------------------------------------------------------------------
/FileBasics/FileBasics.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {D352601A-7898-41C8-BE42-C99A4CA992B5}
16 | FileBasics
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/FileBasics/FileBasics.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/FileBasics/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define MAXSTRLEN 200
4 | #define FILENAME "test.txt"
5 |
6 | void readlines() {
7 | FILE *fp = fopen(FILENAME, "r");
8 | char line[MAXSTRLEN];
9 |
10 | if (fp != NULL) {
11 | while (fgets(line, sizeof(line), fp) != 0) {
12 | fputs(line, stdout);
13 | }
14 | fclose(fp);
15 | } else {
16 | printf("File %s cannot be opened!", FILENAME);
17 | }
18 | }
19 |
20 | void writelines() {
21 | FILE *fp;
22 |
23 | fp = fopen(FILENAME, "w");
24 | fputs("Hello world\n", fp);
25 | fputs("Goodbye Mars\n", fp);
26 | fclose(fp);
27 | }
28 |
29 | void clearfile() {
30 | FILE *fp;
31 |
32 | fp = fopen(FILENAME, "w");
33 | fclose(fp);
34 | }
35 |
36 | void deletefile() {
37 | if (remove(FILENAME) == 0) {
38 | printf("%s file deleted.\n", FILENAME);
39 | } else {
40 | printf("Unable to delete the file: %s.\n", FILENAME);
41 | }
42 | }
43 |
44 | int main(int argc, char **argv) {
45 | // deletefile();
46 | // clearfile();
47 | writelines();
48 | readlines();
49 | return 0;
50 | }
--------------------------------------------------------------------------------
/FileBasics/test.txt:
--------------------------------------------------------------------------------
1 | Hello world
2 | Goodbye Mars
3 |
--------------------------------------------------------------------------------
/FileSearchStr/FileSearchStr.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Resource Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/FileSearchStr/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define FILENAME "sonnet.txt"
5 | #define MAXSTRLEN 200
6 |
7 | // returns index (0-based) of first char of searchstring in sourcestring
8 | // or -1 if searchstring is not found
9 | static int searchstring(char searchstr[], char sourcestr[]) {
10 | char *ptrtostr;
11 | int foundat;
12 |
13 | foundat = -1;
14 | ptrtostr = strstr(sourcestr, searchstr);
15 | if (ptrtostr != 0) {
16 | foundat = (int)((ptrtostr - sourcestr));
17 | }
18 | return foundat;
19 | }
20 |
21 | void findstrings(char *fileName, char *ss) {
22 | FILE *f;
23 | int count;
24 | char line[MAXSTRLEN];
25 |
26 | f = fopen(fileName, "r"); // open file read only
27 | if (f == NULL) {
28 | printf("Can't open the file: '%s'\n", FILENAME);
29 | } else {
30 | count = 0; // initialize the count
31 | while (fgets(line, MAXSTRLEN, f) != 0) {
32 | if (searchstring(ss, line) >= 0) {
33 | count++;
34 | }
35 | }
36 | printf("'%s' was found in %d lines\n", ss, count);
37 | fclose(f); // close it
38 | }
39 | }
40 |
41 | int main(int argc, char **argv) {
42 | findstrings(FILENAME, "then");
43 | findstrings(FILENAME, "my");
44 | findstrings(FILENAME, "snodgrass");
45 | return 0;
46 | }
--------------------------------------------------------------------------------
/FileSearchStr/sonnet.txt:
--------------------------------------------------------------------------------
1 | When in disgrace with fortune and men's eyes
2 | I all alone beweep my outcast state,
3 | And trouble deaf heaven with my bootless cries,
4 | And look upon myself, and curse my fate,
5 | Wishing me like to one more rich in hope,
6 | Featured like him, like him with friends possessed,
7 | Desiring this man's art, and that man's scope,
8 | With what I most enjoy contented least;
9 | Yet in these thoughts my self almost despising,
10 | Haply I think on thee, and then my state,
11 | Like to the lark at break of day arising
12 | From sullen earth, sings hymns at heaven's gate;
13 | For thy sweet love remembered such wealth brings
14 | That then I scorn to change my state with kings.
--------------------------------------------------------------------------------
/FileStats/FileStats.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {AF7911DE-AFB9-4AA0-8AFD-C52EDA11C2B0}
16 | FileStats
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/FileStats/FileStats.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Resource Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/FileStats/empty.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/C-Projects/2af7e4ae1838a0b36d3c267198d1fab702d2ee0d/FileStats/empty.txt
--------------------------------------------------------------------------------
/FileStats/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define MAXSTRLEN 200
4 | #define FILENAME "sonnet.txt"
5 | #define EMPTYFILENAME "empty.txt"
6 | #define INVALIDFILENAME "not_here.txt"
7 |
8 | void linecount(char *fn) {
9 | int numlines = 0;
10 | char line[MAXSTRLEN];
11 |
12 | FILE *fp = fopen(fn, "r");
13 | if (fp != NULL) {
14 | while (fgets(line, sizeof(line), fp) != 0) {
15 | numlines++;
16 | }
17 | fclose(fp);
18 | printf("%s contains %d lines of text.\n", fn, numlines);
19 | } else {
20 | printf("File %s cannot be opened!\n", fn);
21 | }
22 | }
23 |
24 | int main(int argc, char **argv) {
25 | linecount(FILENAME);
26 | linecount(EMPTYFILENAME);
27 | linecount(INVALIDFILENAME);
28 | return 0;
29 | }
--------------------------------------------------------------------------------
/FileStats/sonnet.txt:
--------------------------------------------------------------------------------
1 | When in disgrace with fortune and men's eyes
2 | I all alone beweep my outcast state,
3 | And trouble deaf heaven with my bootless cries,
4 | And look upon myself, and curse my fate,
5 | Wishing me like to one more rich in hope,
6 | Featured like him, like him with friends possessed,
7 | Desiring this man's art, and that man's scope,
8 | With what I most enjoy contented least;
9 | Yet in these thoughts my self almost despising,
10 | Haply I think on thee, and then my state,
11 | Like to the lark at break of day arising
12 | From sullen earth, sings hymns at heaven's gate;
13 | For thy sweet love remembered such wealth brings
14 | That then I scorn to change my state with kings.
--------------------------------------------------------------------------------
/Functions/Functions.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {2DE7EA2D-D426-4226-9E9D-50E9CC6F215B}
16 | Functions
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Functions/Functions.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Functions/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void sayHello() {
4 | printf("Hello\n");
5 | }
6 |
7 | void greet(char aName[]) {
8 | printf("Hello %s\n", aName);
9 | }
10 |
11 | int add(int num1, int num2) {
12 | num1 = num1 + num2;
13 | return num1;
14 | }
15 |
16 | double divide(double num1, double num2) {
17 | return num1 / num2;
18 | }
19 |
20 | int main(int argc, char **argv) {
21 | double result;
22 | int n1;
23 | int n2;
24 | int total;
25 |
26 | n1 = 10;
27 | n2 = 3;
28 |
29 | sayHello();
30 | greet("Fred");
31 |
32 | total = add(n1, n2);
33 | printf("%d + %d = %d\n", n1, n2, total);
34 | result = divide(100, 3);
35 | printf("Result = %f\n", result);
36 | return 0;
37 | }
--------------------------------------------------------------------------------
/GetInput/GetInput.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {BE702A45-1B1F-4FEE-ABB3-2A4E45402F11}
16 | GetInput
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/GetInput/GetInput.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/GetInput/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char *gets(char*); // no longer defined in C11 standard
4 |
5 | void flush_input() {
6 | int ch;
7 |
8 | while ((ch = getchar()) != '\n' && ch != EOF);
9 | }
10 |
11 | void getinput_with_gets() {
12 | char firstname[5];
13 | char lastname[5];
14 |
15 | printf("Enter your first name:");
16 | gets(firstname);
17 | printf("Enter your last name:");
18 | gets(lastname);
19 | printf("Hello, %s, %s\n", firstname, lastname);
20 | }
21 |
22 |
23 | void getinput_with_fgets() {
24 | char firstname[5];
25 | char lastname[5];
26 |
27 | printf("Enter your first name:");
28 | fgets(firstname, 5, stdin);
29 | printf("Enter your last name:");
30 | // fflush(stdin); // This function may not (invariably) work with input!
31 | // Try commenting out the next line
32 | flush_input();
33 | fgets(lastname, 5, stdin);
34 | // Try commenting out the next line
35 | flush_input();
36 | printf("Hello, %s, %s\n", firstname, lastname);
37 | }
38 |
39 | int main(int argc, char **argv) {
40 | /*
41 | Try uncommenting to the call (below) to
42 | getinput_with_gets();
43 | When promptedm enter:
44 | 1234567890
45 | And:
46 | abcdfeghi
47 |
48 | The actual behaviour of the program is unpredictable. In all probability
49 | it will crash.
50 |
51 | Now comment out that function call to execute
52 | getinput_with_fgets();
53 | Try entering the same data when prompted. Now the entered strings are truncated.
54 | But the program will not crash.
55 | */
56 |
57 | // getinput_with_gets();
58 | getinput_with_fgets();
59 | return 0;
60 | }
--------------------------------------------------------------------------------
/HeaderFiles/HeaderFiles.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
--------------------------------------------------------------------------------
/HeaderFiles/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mystring.h"
3 |
4 | char b[BUFSIZE];
5 | char teststring[] = "Hello world";
6 |
7 | int main(int argc, char **argv) {
8 | int i;
9 | int stringpos;
10 |
11 | printf("starting...\n");
12 | i = readln(b, sizeof(b));
13 | printf("b=%s; i=%d\n", b, i);
14 | stringpos = searchstring(b, teststring);
15 | if (stringpos > -1) {
16 | printf("'%s' found in '%s' at index #%d\n", b, teststring, stringpos);
17 | } else {
18 | printf("'%s' not found in '%s'\n", b, teststring);
19 | }
20 | return 0;
21 | }
--------------------------------------------------------------------------------
/HeaderFiles/mystring.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "mystring.h"
4 |
5 | // reads line from input and returns length of string
6 | int readln(char s[], int maxlen) {
7 | char ch;
8 | int i;
9 | int chars_remain;
10 |
11 | i = 0;
12 | chars_remain = 1;
13 | while (chars_remain) {
14 | ch = getchar();
15 | if ((ch == '\n') || (ch == EOF)) {
16 | chars_remain = 0;
17 | } else if (i < maxlen - 1) {
18 | s[i] = ch;
19 | i++;
20 | }
21 | }
22 | s[i] = '\0';
23 | return i;
24 | }
25 |
26 | // returns index (0-based) of first char of searchstring in sourcestring
27 | // or -1 if searchstring is not found
28 | int searchstring(char searchstr[], char sourcestr[]) {
29 | char *ptrtostr;
30 | int foundat;
31 |
32 | foundat = -1;
33 | ptrtostr = strstr(sourcestr, searchstr);
34 | if (ptrtostr != NULL) {
35 | foundat = (int)((ptrtostr - sourcestr));
36 | }
37 | return foundat;
38 | }
39 |
--------------------------------------------------------------------------------
/HeaderFiles/mystring.h:
--------------------------------------------------------------------------------
1 | #define BUFSIZE 100
2 | int readln(char[], int);
3 | int searchstring(char[], char[]);
--------------------------------------------------------------------------------
/HelloWorld/HelloWorld.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {FEA6ADCB-91A7-4C0C-925D-337CFD13DF8E}
16 | HelloWorld
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/HelloWorld/HelloWorld.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/HelloWorld/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | main() {
4 | printf("hello world\n");
5 | }
--------------------------------------------------------------------------------
/HelloWorldAgain/HelloWorldAgain.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {25FA6F70-61D3-43F6-BD19-EE5EFFF52B25}
16 | HelloWorldAgain
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/HelloWorldAgain/HelloWorldAgain.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/HelloWorldAgain/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | printf("hello world\n");
5 | return 0;
6 | }
--------------------------------------------------------------------------------
/HelloWorldArgs/HelloWorldArgs.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {57CBF06F-6C6D-4053-8D5F-7CDFCFCBB48C}
16 | HelloWorldArgs
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/HelloWorldArgs/HelloWorldArgs.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/HelloWorldArgs/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* This program displays any
4 | * arguments that were passed to it
5 | */
6 |
7 | int main(int argc, char **argv) {
8 | int i;
9 |
10 | for (i = 0; i < argc; i++) {
11 | printf("Hello World! argc=%d arg %d is %s\n", argc, i, argv[i]); // prints arg at index i
12 | }
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/LogicalOperators/LogicalOperators.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {BF732B88-9185-4156-8032-91BA63EB6CC7}
16 | LogicalOperators
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/LogicalOperators/LogicalOperators.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LogicalOperators/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | int age;
5 | int number_of_children;
6 | double salary;
7 |
8 | age = 25;
9 | number_of_children = 1;
10 | salary = 20000.00;
11 |
12 | if ((age <= 30) && (salary >= 30000)) {
13 | printf("You are a rich young person\n");
14 | } else {
15 | printf("You are not a rich young person\n");
16 | }
17 |
18 | if ((age <= 30) || (salary >= 30000)) {
19 | printf("You are either rich or young or both\n");
20 | } else {
21 | printf("You are neither rich nor young\n");
22 | }
23 |
24 | if ((age <= 30) && (salary >= 30000) && (number_of_children != 0)) {
25 | printf("You are a rich young parent\n");
26 | } else {
27 | printf("You are not a rich young parent\n");
28 | }
29 |
30 | return 0;
31 | }
--------------------------------------------------------------------------------
/MultiDimensionArrays/MultiDimensionArrays.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {553C0C49-6054-4B03-8931-5F7C90AE644A}
16 | MultiDimensionArrays
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/MultiDimensionArrays/MultiDimensionArrays.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/MultiDimensionArrays/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int grid[3][5] = {
4 | { 1, 2, 3, 4, 5 },
5 | { 6, 7, 8, 9, 10 },
6 | { 11, 12, 13, 14, 15 }
7 | };
8 |
9 | int main(int argc, char **argv) {
10 | int row;
11 | int column;
12 |
13 | for (row = 0; row < 3; row++) {
14 | printf("--- row %d --- \n", row);
15 | for (column = 0; column < 5; column++) {
16 | printf("column[%d], value=%d\n", column, grid[row][column]);
17 | // uncomment the code below to see how to break out of the inner 'for' loop
18 | // If I were to put a break here it would break out of the INNER 'for'
19 | // loop only
20 | /*
21 | if (column == 2) {
22 | break;
23 | }
24 | */
25 | }
26 | }
27 | return 0;
28 | }
--------------------------------------------------------------------------------
/NamingConventions/NamingConventions.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {F638ABEE-E42C-4F5B-95DD-501C96204B68}
16 | NamingConventions
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/NamingConventions/NamingConventions.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/NamingConventions/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define somevalue 10
4 | #define some_other_value 15
5 | #define SERVICE_CHARGE 33
6 |
7 | int do_something(int x) {
8 | return x + somevalue;
9 | }
10 |
11 | int Do_Something(int x) {
12 | return x + some_other_value;
13 | }
14 |
15 | int calculate_grand_total(int subtotal) {
16 | int grand_total;
17 |
18 | grand_total = subtotal + SERVICE_CHARGE;
19 | return grand_total;
20 | }
21 |
22 | int main(int argc, char **argv) {
23 | printf("%d\n", do_something(500));
24 | printf("%d\n", Do_Something(600));
25 | printf("%d\n", calculate_grand_total(700));
26 | return 0;
27 | }
--------------------------------------------------------------------------------
/Operators/Operators.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {F656A5E6-AB25-4EF1-8129-D5DFD0A181E1}
16 | Operators
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Operators/Operators.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Operators/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void showPrefixAndPostfixOps() {
4 | int num1, num2;
5 |
6 | printf("\nPrefix and Postfix operators... (num1 = 10)");
7 | num1 = 10;
8 | num2 = num1++; // num2 = 10, num1 = 11
9 | printf("\nnum2 = num1++; so num2 = %d and num1 = %d", num2, num1);
10 |
11 | num1 = 10;
12 | num2 = ++num1; // num2 = 11, num1 = 11
13 | printf("\nnum2 = ++num1; so num2 = %d and num1 = %d", num2, num1);
14 | }
15 |
16 | int main(int argc, char **argv) {
17 | int age;
18 | int bonus;
19 |
20 | int a;
21 | int b;
22 | a = 10;
23 | b = 2;
24 |
25 | age = 70;
26 | if (age > 45) {
27 | bonus = 1000;
28 | } else {
29 | bonus = 500;
30 | }
31 | printf("Your age is %d, so your bonus is %d.\n", age, bonus);
32 |
33 | if (age <= 70) {
34 | printf("You are one of our youngest employees!\n");
35 | }
36 |
37 | if (bonus >= 1000) {
38 | printf("You've earned a high bonus!\n");
39 | }
40 |
41 | printf("\nHere are examples of some compound assignment operators...\n");
42 | a = a + b;
43 | printf("\na + b : %d\n", a);
44 | a = 10;
45 | a += b;
46 | printf("a += b : %d\n", a);
47 | a = 10;
48 | a = a - b;
49 | printf("a - b : %d\n", a);
50 | a = 10;
51 | a -= b;
52 | printf("a -= b : %d\n", a);
53 | a = 10;
54 | a = a * b;
55 | printf("a * b : %d\n", a);
56 | a = 10;
57 | a *= b;
58 | printf("a *= b : %d\n", a);
59 | a = 10;
60 | a = a / b;
61 | printf("a/b : %d\n", a);
62 | a = 10;
63 | a /= b;
64 | printf("a /= b : %d\n", a);
65 | a = 10;
66 | a++;
67 | printf("a++ : %d\n", a);
68 | a = 10;
69 | a--;
70 | printf("a-- : %d\n", a);
71 |
72 | showPrefixAndPostfixOps();
73 | return(0);
74 | }
--------------------------------------------------------------------------------
/Printf/Printf.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {3C9E80F2-C6E6-436D-8E8C-818B26C00EAE}
16 | printf
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Printf/Printf.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Printf/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | printf("hello world\n");
5 | puts("hello world again");
6 | printf("There are %d bottles standing on the %s.\n", 20, "wall");
7 | return 0;
8 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | CProjects
--------------------------------------------------------------------------------
/ReadFile/ReadFile.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {C8AA6FAB-E33C-4CD2-98C5-2DC83D0FDA0E}
16 | ReadFile
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/ReadFile/ReadFile.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Resource Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ReadFile/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void readin(char *filename) {
5 | FILE *f;
6 | long size;
7 | char *b;
8 | size_t items_read; // size_t is a long unsigned int
9 | int linecount;
10 | int i;
11 |
12 | linecount = 0;
13 | f = fopen(filename, "rb"); // open file read only in binary mode
14 | if (f == NULL){ // get out if no good
15 | printf("Cannot open '%s'\n", filename);
16 | } else {
17 | fseek(f, 0, SEEK_END); // seek to end of file
18 | size = ftell(f); // get the current position (now at the end of the file)
19 | rewind(f); // move the seek pointer to the start
20 | b = malloc(size); // alloc some memory
21 | if (b == NULL) {
22 | printf("help!!\n");
23 | } else {
24 | items_read = fread(b, 1, size, f); // read the lot in
25 | fclose(f); // close it
26 | for (i = 0; i < size; i++) {
27 | if (b[i] == '\n') {
28 | linecount++;
29 | }
30 | }
31 | linecount++; // the last line doesn't have a line feed at the end
32 | printf("number of lines was %d with %d chars (%d items read).\n", linecount, i, items_read);
33 | free(b);
34 | }
35 | }
36 | }
37 |
38 | int main(int argc, char **argv) {
39 | readin("sonnet.txt");
40 | return 0;
41 | }
--------------------------------------------------------------------------------
/ReadFile/sonnet.txt:
--------------------------------------------------------------------------------
1 | When in disgrace with fortune and men's eyes
2 | I all alone beweep my outcast state,
3 | And trouble deaf heaven with my bootless cries,
4 | And look upon myself, and curse my fate,
5 | Wishing me like to one more rich in hope,
6 | Featured like him, like him with friends possessed,
7 | Desiring this man's art, and that man's scope,
8 | With what I most enjoy contented least;
9 | Yet in these thoughts my self almost despising,
10 | Haply I think on thee, and then my state,
11 | Like to the lark at break of day arising
12 | From sullen earth, sings hymns at heaven's gate;
13 | For thy sweet love remembered such wealth brings
14 | That then I scorn to change my state with kings.
--------------------------------------------------------------------------------
/ReadLine/ReadLine.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {3A350FEB-1E50-4EA9-97A2-DC78D1DF570C}
16 | ReadLine
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/ReadLine/ReadLine.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ReadLine/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | /*
3 | The readln() function reads chars up to length defined by STRLEN
4 | It truncates strings that are longer. It avoids the problems
5 | found when using fgets() with strings that are shorter.
6 | */
7 |
8 | #define STRLEN 5
9 |
10 |
11 | // My first attempt!!!
12 | /*
13 | int readln(char s[], int maxlen) {
14 | int len_s;
15 | fgets(s, maxlen, stdin);
16 | len_s = strlen(s);
17 | if (s[len_s - 1] == '\n') {
18 | s[len_s - 1] = '\0';
19 | len_s -= 1;
20 | }
21 | rewind(stdin); // This flushes the keyboard buffer (on Windows anyway!)
22 | return len_s;
23 | }
24 | */
25 |
26 | int readln(char s[], int maxlen) {
27 | char ch;
28 | int i;
29 | int chars_remain;
30 |
31 | i = 0;
32 | chars_remain = 1;
33 | while (chars_remain) {
34 | ch = getchar();
35 | if ((ch == '\n') || (ch == EOF)) {
36 | chars_remain = 0;
37 | } else if (i < maxlen - 1) {
38 | s[i] = ch;
39 | i++;
40 | }
41 | }
42 | s[i] = '\0';
43 | return i;
44 | }
45 |
46 | int main(int argc, char **argv) {
47 | char firstname[STRLEN];
48 | char lastname[STRLEN];
49 | int len_firstname;
50 | int len_lastname;
51 |
52 | printf("Enter your first name:");
53 | len_firstname = readln(firstname, STRLEN);
54 | printf("Enter your last name:");
55 | len_lastname = readln(lastname, STRLEN);
56 | printf("Hello, %s, %s\n", firstname, lastname);
57 | printf("Length of firstname = %d, lastname = %d", len_firstname, len_lastname);
58 | return 0;
59 | }
--------------------------------------------------------------------------------
/ReturnStrings/ReturnStrings.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {53A5091F-59B5-402B-89E1-635BD279B69A}
16 | ReturnStrings
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/ReturnStrings/ReturnStrings.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ReturnStrings/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #define MAXSTRLEN 100
6 |
7 | char greeting[MAXSTRLEN];
8 |
9 | char *string_function_dynamic(char *astring) {
10 | char *s;
11 |
12 | s = malloc(MAXSTRLEN);
13 | s[0] = 0; // need this to initialize the buffer created by malloc
14 | strcat(s, "hello ");
15 | // With the Microsoft Compiler, strcat_s is the preferred 'safe' alternative to
16 | // strcat (see example below) but this function is not supported by all C compilers
17 | // strcat_s(s, MAXSTRLEN, "hello ");
18 | strcat(s, astring);
19 | strcat(s, "\n");
20 | return s;
21 | }
22 |
23 | char *string_function(char astring[]) {
24 | strcat(greeting, "hello ");
25 | strcat(greeting, astring);
26 | strcat(greeting, "\n");
27 | return greeting;
28 | }
29 |
30 | int main(int argc, char **argv) {
31 | printf(string_function("Fred"));
32 | printf(string_function_dynamic("Mary"));
33 | return 0;
34 | }
--------------------------------------------------------------------------------
/Scope/Scope.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Scope/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "mystring.h"
3 |
4 | // Global scope
5 | char b[MAXSTRLEN];
6 | char teststring[] = "Hello world";
7 | int num = 10;
8 |
9 | void addnumbers() {
10 | static int x = 0;
11 | int y = 0;
12 |
13 | x++;
14 | y++;
15 | printf("In addnumbers() x=%d, y=%d\n", x, y);
16 | }
17 |
18 | void globalnum() {
19 | printf("In globalnum, num is %d\n", num);
20 | }
21 |
22 | void localnum() {
23 | int num;
24 |
25 | num = 100;
26 | printf("In localnum, num is %d\n", num);
27 | }
28 |
29 | int main(int argc, char **argv) {
30 | int i;
31 | //int stringpos;
32 |
33 | printf("starting...\n");
34 | i = readln(b, sizeof(b));
35 | printf("b=%s; i=%d\n", b, i);
36 | /* // --- This can't be run as long as searchstring() is a static function
37 | stringpos = searchstring(b, teststring);
38 | if(stringpos > -1){
39 | printf( "'%s' found in '%s' at index #%d\n", b, teststring, stringpos);
40 | }else{
41 | printf( "'%s' not found in '%s'\n", b, teststring);
42 | }
43 | */
44 | printf(findsubstring(b, teststring));
45 | localnum();
46 | globalnum();
47 | addnumbers();
48 | addnumbers();
49 | addnumbers();
50 | return 0;
51 | }
--------------------------------------------------------------------------------
/Scope/mystring.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "mystring.h"
4 |
5 | // reads line from input and returns length of string
6 | int readln(char s[], int maxlen) {
7 | char ch;
8 | int i;
9 | int chars_remain;
10 |
11 | i = 0;
12 | chars_remain = 1;
13 | while (chars_remain) {
14 | ch = getchar();
15 | if ((ch == '\n') || (ch == EOF)) {
16 | chars_remain = 0;
17 | } else if (i < maxlen - 1) {
18 | s[i] = ch;
19 | i++;
20 | }
21 | }
22 | s[i] = '\0';
23 | return i;
24 | }
--------------------------------------------------------------------------------
/Scope/mystring.h:
--------------------------------------------------------------------------------
1 | #define MAXSTRLEN 200
2 | int readln(char[], int);
3 | char * findsubstring(char[], char[]);
4 | // int searchstring(char[], char[]);
--------------------------------------------------------------------------------
/Scope/mystringutils.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "mystring.h"
5 |
6 | // returns index (0-based) of first char of searchstring in sourcestring
7 | // or -1 if searchstring is not found
8 | static int searchstring(char searchstr[], char sourcestr[]) {
9 | char *ptrtostr;
10 | int foundat;
11 |
12 | foundat = -1;
13 | ptrtostr = strstr(sourcestr, searchstr);
14 | if (ptrtostr != NULL) {
15 | foundat = (int)((ptrtostr - sourcestr));
16 | }
17 | return foundat;
18 | }
19 |
20 | char *findsubstring(char searchstr[], char sourcestr[]) {
21 | char *s;
22 | int stringpos;
23 |
24 | s = malloc(MAXSTRLEN);
25 | s[0] = 0; // need this to initialize the buffer created by malloc
26 | stringpos = searchstring(searchstr, sourcestr);
27 | if (stringpos > -1) {
28 | sprintf(s, "'%s' found in '%s' at index #%d\n", searchstr, sourcestr, stringpos);
29 | } else {
30 | sprintf(s, "'%s' not found in '%s'\n", searchstr, sourcestr);
31 | }
32 | return s;
33 | }
--------------------------------------------------------------------------------
/StringFunctions/StringFunctions.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {434650C5-E9A2-49E3-B6DD-1ABCC4CA50FD}
16 | StringFunctions
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/StringFunctions/StringFunctions.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/StringFunctions/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define MAXSTRLEN 200
5 |
6 | char mystring[] = "On the 2nd day of Christmas my true love gave to me, 2 turtle doves and a partridge in a pear tree.";
7 | char tens[] = " 10 20 30 40 50";
8 | char nums[] = "123456789012345678901234567890123456789012345678901234567890";
9 | // I will concat strings to msg1 and msg2 so I need to set aside enough memory (the array size)
10 | // to accomodate the additional characters...
11 | char msg1[MAXSTRLEN] = "Result1: ";
12 | char msg2[MAXSTRLEN] = "Result2: ";
13 | char myotherstr[6];
14 |
15 | void showstring() {
16 | printf("\n\n%s\n", mystring);
17 | printf("%s\n%s\n", tens, nums);
18 | }
19 |
20 | void searchstring(char searchstr[]) {
21 | char *ptrtostr;
22 | int foundat;
23 | ptrtostr = strstr(mystring, searchstr);
24 | foundat = (int)((ptrtostr - mystring) + 1);
25 | if (ptrtostr != NULL)
26 | printf("\n'%s' found at position %d\n", searchstr, foundat);
27 | else
28 | printf("\n'%s' not found\n", searchstr);
29 | }
30 |
31 | void copystring() {
32 | // Many modern C11 compilers provide safer string functions ending with _s
33 | // This example shows strncpy_s but this is not yet supported by all compilers
34 | /* strncpy_s(myotherstr, 6, "Easter", 4);
35 | printf("\nstrncpy_s: Copied this string: '%s'", myotherstr); */
36 | myotherstr[0] = 0;
37 | strncpy(myotherstr, "Easter", 4);
38 | printf("\nCopied this string: '%s'", myotherstr);
39 | }
40 |
41 | void concatstring() {
42 | strcat(msg1, "Easter");
43 | printf("\n\nstrcat: '%s'", msg1);
44 | strncat(msg2, "Easter", 4);
45 | printf("\nstrncat: '%s'\n", msg2);
46 | }
47 |
48 | int main(int argc, char **argv) {
49 | printf("Length of mystring = %d", strlen(mystring));
50 | printf("\nLength of 'Hello' = %d", strlen("Hello"));
51 | showstring();
52 | searchstring("2nd");
53 | searchstring("Christmas");
54 | searchstring("Easter");
55 | copystring();
56 | concatstring();
57 | return 0;
58 | }
--------------------------------------------------------------------------------
/StringIndex/StringIndex.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {9D8888B9-F0DF-4489-A08B-BD0A3F62186D}
16 | StringIndex
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/StringIndex/StringIndex.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/StringIndex/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | char str1[] = "Hello";
5 | char str2[] = "Goodbye\0 world";
6 |
7 | void showstring(char *str) {
8 | int i;
9 | int len = strlen(str);
10 |
11 | printf("Length of %s is %d.\n", str, len);
12 | for (i = 0; i <= len; i++) {
13 | if (str[i] == '\0') {
14 | printf("char[%d] = NULL\n", i);
15 | } else {
16 | printf("char[%d] = %c\n", i, str[i]);
17 | }
18 | }
19 | }
20 |
21 | int main(int argc, char **argv) {
22 | showstring(str1);
23 | showstring(str2);
24 | printf("%s\n", str1);
25 | printf("%s\n", str2);
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/StringsAndAddresses/StringsAndAddresses.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {4842BDD0-37F5-4223-B3BE-0088107872D4}
16 | StringsAndAddresses
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/StringsAndAddresses/StringsAndAddresses.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/StringsAndAddresses/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | char str1[] = "Hello";
5 | char *str2 = "Goodbye";
6 |
7 | printf("%d %s\n", str1, str1);
8 | printf("%d %s\n", str2, str2);
9 | // str2 = &str1;
10 | str2 = str1;
11 | printf("%d %s\n", str1, str1);
12 | printf("%d %s\n", str2, str2);
13 | printf("str1[] - Address of str1=%d, str1(int)=%d, str1(string)=%s,\n*str2 - Address of str2=%d, str2(int)=%d, str2(string)=%s", &str1, str1, str1, &str2, str2, str2);
14 |
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/StringsAndPointers/StringsAndPointers.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {5038561C-CFB3-4D2E-87AD-872A2B01C3FB}
16 | StringsAndPointers
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/StringsAndPointers/StringsAndPointers.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/StringsAndPointers/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv) {
4 | char str1[] = "Hello";
5 | char *str2 = "Goodbye";
6 |
7 | // str2 = &str1;
8 | // str2 = str1;
9 | printf("%d %d %s\n", &str1, str1, str1);
10 | printf("%d %d %s\n", &str2, str2, str2);
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/Structs/Structs.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {AC0DEE6E-92DD-4415-86B1-D219BF9B5AC0}
16 | Structs
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Structs/Structs.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Structs/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define NUMBER_OF_CDS 4
5 |
6 | struct cd {
7 | char name[50];
8 | char artist[50];
9 | int trackcount;
10 | int rating;
11 | };
12 |
13 | struct cd cd_collection[NUMBER_OF_CDS];
14 |
15 | void create_cdcollection() {
16 | strcpy(cd_collection[0].name, "Great Hits");
17 | strcpy(cd_collection[0].artist, "Polly Darton");
18 | cd_collection[0].trackcount = 20;
19 | cd_collection[0].rating = 10;
20 |
21 | strcpy(cd_collection[1].name, "Mega Songs");
22 | strcpy(cd_collection[1].artist, "Lady Googoo");
23 | cd_collection[1].trackcount = 18;
24 | cd_collection[1].rating = 7;
25 |
26 | strcpy(cd_collection[2].name, "The Best Ones");
27 | strcpy(cd_collection[2].artist, "The Warthogs");
28 | cd_collection[2].trackcount = 24;
29 | cd_collection[2].rating = 4;
30 |
31 | strcpy(cd_collection[3].name, "Songs From The Shows");
32 | strcpy(cd_collection[3].artist, "The Singing Swingers");
33 | cd_collection[3].trackcount = 22;
34 | cd_collection[3].rating = 9;
35 | }
36 |
37 | void display_cdcollection() {
38 | int i;
39 | struct cd thiscd;
40 |
41 | for (i = 0; i < NUMBER_OF_CDS; i++) {
42 | thiscd = cd_collection[i];
43 | printf("CD #%d: '%s' by %s has %d tracks. My rating = %d\n", i, thiscd.name, thiscd.artist, thiscd.trackcount, thiscd.rating);
44 | }
45 | }
46 |
47 | int main(int argc, char **argv) {
48 | create_cdcollection();
49 | display_cdcollection();
50 | return 0;
51 | }
--------------------------------------------------------------------------------
/SwitchBug/SwitchBug.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {F8E20B85-74A9-4DC3-B08A-CD1CB9462418}
16 | SwitchBug
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/SwitchBug/SwitchBug.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/SwitchBug/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void switchtest(int x) {
4 | int i = 0;
5 |
6 | switch (x) {
7 | case 0:
8 | i += 0;
9 | break;
10 | case 1:
11 | i += 1;
12 | break;
13 | default:
14 | i += 100;
15 | // break;
16 | case 2:
17 | i += 2;
18 | break;
19 | }
20 | printf("x=%d, i=%d\n", x, i);
21 | }
22 |
23 | int main(int argc, char** argv) {
24 | for (int i = 0; i < 4; i++) {
25 | switchtest(i);
26 | }
27 | return 0;
28 | }
--------------------------------------------------------------------------------
/SwitchCase/SwitchCase.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {FCE4C4F0-141B-45FB-AFCD-0AF385E61AC4}
16 | SwitchCase
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/SwitchCase/SwitchCase.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/SwitchCase/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char *chartype;
4 |
5 | void findchartype2(char c) {
6 | switch (c) {
7 | case '\0':
8 | chartype = "Null";
9 | break;
10 | case '\t':
11 | chartype = "Tab";
12 | break;
13 | case '\n':
14 | chartype = "LineFeed";
15 | break;
16 | case '\r':
17 | chartype = "Carriage Return";
18 | break;
19 | case ' ':
20 | chartype = "Space";
21 | break;
22 | case '0':
23 | case '1':
24 | case '2':
25 | case '3':
26 | case '4':
27 | case '5':
28 | case '6':
29 | case '7':
30 | case '8':
31 | case '9':
32 | chartype = "Number";
33 | break;
34 | /*
35 | case 'A' ... 'Z':
36 | chartype = "Uppercase Letter";
37 | break;
38 | case 'a' ... 'z':
39 | chartype = "Lowercase Letter";
40 | break;
41 | */
42 | default:
43 | chartype = "Character";
44 | break;
45 | }
46 | }
47 |
48 |
49 | void findchartype(int i) {
50 | switch (i) {
51 | case 0:
52 | chartype = "Null";
53 | break;
54 | case 7:
55 | chartype = "Bell";
56 | break;
57 | case 8:
58 | chartype = "BackSpace";
59 | break;
60 | case 9:
61 | chartype = "Tab";
62 | break;
63 | case 10:
64 | chartype = "LineFeed";
65 | break;
66 | case 13:
67 | chartype = "Carriage Return";
68 | break;
69 | case 32:
70 | chartype = "Space";
71 | break;
72 | case 48:
73 | case 49:
74 | case 50:
75 | case 51:
76 | case 52:
77 | case 53:
78 | case 54:
79 | case 55:
80 | case 56:
81 | case 57:
82 | chartype = "Number";
83 | break;
84 | /*
85 | // These use ranges (values between 65 and 90; values between 97 and 122)
86 | // Ranges in Switch/case are an extension to standard C and this syntax
87 | // is not supported by all C compilers
88 | case 65 ... 90:
89 | chartype = "Uppercase Letter";
90 | break;
91 | case 97 ... 122:
92 | chartype = "Lowercase Letter";
93 | break;
94 | */
95 | default:
96 | chartype = "Character"; // This is a single line comment
97 | break;
98 | }
99 | }
100 |
101 |
102 | void showascii() {
103 | int i;
104 | char c;
105 |
106 | for (i = 0; i <= 127; i++) {
107 | findchartype(i);
108 | printf("%d = %c\t\t[%s]\n", i, i, chartype);
109 | }
110 | printf("\nPress Enter to continue...\n");
111 | c = getchar();
112 | for (i = 0; i <= 127; i++) {
113 | findchartype2(i);
114 | printf("%d = %c\t\t[%s]\n", i, i, chartype);
115 | }
116 | }
117 |
118 | int main(int argc, char **argv) {
119 | showascii();
120 | return 0;
121 | }
--------------------------------------------------------------------------------
/TestAge1/TestAge1.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {69CDA7D4-6168-47DF-ABA2-BE2A12FD2321}
16 | TestAge1
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/TestAge1/TestAge1.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/TestAge1/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | char *gets(char*); // no longer defined in C11 standard
5 |
6 | int main(int argc, char **argv) {
7 | char agestring[10];
8 | int age;
9 | int bonus;
10 |
11 | printf("Enter your age : ");
12 | gets(agestring);
13 | age = atoi(agestring);
14 | if (age > 45) {
15 | bonus = 1000;
16 | } else {
17 | bonus = 500;
18 | }
19 | printf("Your age is %d, so your bonus is %d.\n", age, bonus);
20 |
21 | return(0);
22 | }
--------------------------------------------------------------------------------
/TestAge2/TestAge2.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {E9D5A4FC-5713-43E0-8DF2-96E32D803507}
16 | TestAge2
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/TestAge2/TestAge2.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/TestAge2/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | char *gets(char*); // no longer defined in C11 standard
5 |
6 | int main(int argc, char **argv) {
7 | char agestring[10];
8 | int age;
9 | int bonus;
10 |
11 | printf("Enter your age : ");
12 | gets(agestring);
13 | age = atoi(agestring);
14 | if (age == 0) {
15 | printf("You entered an invalid age, so your bonus cannot be calculated.\n");
16 | } else {
17 | if (age > 45) {
18 | bonus = 1000;
19 | } else {
20 | bonus = 500;
21 | }
22 | printf("Your age is %d, so your bonus is %d.\n", age, bonus);
23 | }
24 |
25 | return(0);
26 | }
--------------------------------------------------------------------------------
/Typedefs/Typedefs.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {2C7DDB2A-2728-4145-8A88-4E93866BA1DC}
16 | Typedefs
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 | true
54 |
55 |
56 |
57 |
58 | Level3
59 | MaxSpeed
60 | true
61 | true
62 | true
63 | true
64 |
65 |
66 | true
67 | true
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Typedefs/Typedefs.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Typedefs/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define NUMBER_OF_CDS 4
5 |
6 | /*
7 | typedef struct cd CD;
8 |
9 | struct cd {
10 | char name[50];
11 | char artist[50];
12 | int trackcount;
13 | int rating;
14 | };
15 | */
16 |
17 | typedef char Str50[50];
18 |
19 | typedef struct cd {
20 | Str50 name;
21 | Str50 artist;
22 | int trackcount;
23 | int rating;
24 | } CD;
25 |
26 | // struct cd cd_collection[NUMBER_OF_CDS];
27 | CD cd_collection[NUMBER_OF_CDS];
28 |
29 | void create_cdcollection() {
30 | strcpy(cd_collection[0].name, "Great Hits");
31 | strcpy(cd_collection[0].artist, "Polly Darton");
32 | cd_collection[0].trackcount = 20;
33 | cd_collection[0].rating = 10;
34 |
35 | strcpy(cd_collection[1].name, "Mega Songs");
36 | strcpy(cd_collection[1].artist, "Lady Googoo");
37 | cd_collection[1].trackcount = 18;
38 | cd_collection[1].rating = 7;
39 |
40 | strcpy(cd_collection[2].name, "The Best Ones");
41 | strcpy(cd_collection[2].artist, "The Warthogs");
42 | cd_collection[2].trackcount = 24;
43 | cd_collection[2].rating = 4;
44 |
45 | strcpy(cd_collection[3].name, "Songs From The Shows");
46 | strcpy(cd_collection[3].artist, "The Singing Swingers");
47 | cd_collection[3].trackcount = 22;
48 | cd_collection[3].rating = 9;
49 | }
50 |
51 | void display_cdcollection() {
52 | int i;
53 | // struct cd thiscd;
54 | CD thiscd;
55 | for (i = 0; i < NUMBER_OF_CDS; i++) {
56 | thiscd = cd_collection[i];
57 | printf("%d CD #%d: '%s' by %s has %d tracks. My rating = %d\n", sizeof(CD), i, thiscd.name, thiscd.artist, thiscd.trackcount, thiscd.rating);
58 | }
59 | }
60 |
61 | int main(int argc, char **argv) {
62 | create_cdcollection();
63 | display_cdcollection();
64 | return 0;
65 | }
--------------------------------------------------------------------------------
/WhileLoops/WhileLoops.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | 15.0
15 | {ACA83A0B-A5E4-412A-98F0-0C256BBE8579}
16 | WhileLoops
17 | 10.0.17763.0
18 |
19 |
20 |
21 | Application
22 | true
23 | v141
24 | MultiByte
25 |
26 |
27 | Application
28 | false
29 | v141
30 | true
31 | MultiByte
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | Level3
50 | Disabled
51 | true
52 | true
53 |
54 |
55 |
56 |
57 | Level3
58 | MaxSpeed
59 | true
60 | true
61 | true
62 | true
63 |
64 |
65 | true
66 | true
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/WhileLoops/WhileLoops.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/WhileLoops/main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void dowhiletest() {
4 | char c;
5 | c = 'y';
6 | printf("\ngetchar() with do...while loop...\n");
7 | do {
8 | printf("\nEnter y or n: ");
9 | c = getchar();
10 | getchar();
11 | } while (c != 'y');
12 | printf("\nThat's all folks!\n");
13 | }
14 |
15 | void whiletest() {
16 | char c;
17 | c = 'y';
18 | printf("\ngetchar() with while loop...\n");
19 | while (c != 'y') {
20 | printf("\nEnter y or n: ");
21 | c = getchar();
22 | getchar();
23 | }
24 | printf("\nThat's all folks!\n");
25 | }
26 |
27 | int main(int argc, char **argv) {
28 | whiletest();
29 | dowhiletest();
30 | return 0;
31 | }
--------------------------------------------------------------------------------
/copyright.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nirzaf/C-Projects/2af7e4ae1838a0b36d3c267198d1fab702d2ee0d/copyright.txt
--------------------------------------------------------------------------------