C Computer Science by Christopher Topalian
C Computer Science by Christopher Topalian
Computer
Science
by
Christopher Andrew Topalian
Copyright 2000-2024
All Rights Reserved
Dedicated
to
God the Father
Download Visual Studio - Search Google
We Go To: google.com
We Go To:
https://visualstudio.microsoft.com/vs/community
Back Next
Project Name - 001
001
D:\_1Code\C\001
We Choose: Add
main.c
D:\_1Code\C\001
main.c
001
#include <stdio.h>
int main()
{
printf("Hi Everyone\n");
return 0;
}
// Building and Running our App
We Left Click on: Local Windows Debugger
D:\_1Code\C\001\x64\Debug\001.exe
#include <stdio.h>
int main()
{
printf("Hi Everyone\n");
return 0;
}
// Input from user
// main.c
#include <stdio.h>
int main()
{
// max name is 100 chars + null terminator
char name[101];
return 0;
}
// Custom Function - askName
// main.c
#include <stdio.h>
int main()
{
// max name is 100 chars + null terminator
char userName[101];
askName(userName);
printf("Hi %s\n", userName);
return 0;
}
// Custom Function - consoleLog
// main.c
#include <stdio.h>
int main()
{
consoleLog("Hi Everyone");
return 0;
}
Header File - We define our function in a header
file for easy use
CONSOLELOG.h
D:\_1Code\C\001
#ifndef CONSOLELOG
#define CONSOLELOG
#include <stdio.h> // printf
#endif
// Our main.c uses CONSOLELOG.h header file
// main.c
#include "CONSOLELOG.h"
#include <stdio.h> // printf
int main()
{
consoleLog("Hi Everyone");
return 0;
}
// PROMPT.h header file
// PROMPT.h
#ifndef PROMPT
#define PROMPT
#include <stdio.h> // scanf_s
#include <string.h> // strlen
#endif
// main.c uses CONSOLELOG.h and PROMPT.h
// main.c
#include "PROMPT.h"
#include "CONSOLELOG.h"
#include <stdio.h> // printf, scanf
int main()
{
// max input is 100 chars + null terminator
char input[101];
return 0;
}
File Structure of the previous Examples
main.c
int main()
{
// create an array of Person structs
struct Person people[] =
{
{ "John", 25 },
{ "Jane", 30 },
{ "Fiona", 28 }
};
return 0;
}
// for loop diagram
Start number
FALSE
Exit test
TRUE
body
increment++
// for loop
// main.c
int main()
{
for (int i = 1; i <= 100; i++)
{
printf("%d ", i);
printf("\n");
}
return 0;
}
// while loop diagram
start
FALSE
Exit test
TRUE
body
// while loop
// main.c
int main()
{
for (int i = 1; i <= 100; i++)
{
printf("%d ", i);
printf("\n");
}
return 0;
}
// if else - strcmp, without null terminating the
string
// main.c
int main()
{
char name[101]; // buffer to store the name
if (strcmp(name, "Chris") == 0)
{
printf("Hi Chris.\nIt is good that you are
visiting Earth.\n");
}
else
{
printf("Howdy %s. Tell Chris to Sign in
later.\n", name);
}
return 0;
}
// if else - strcmp, null terminating the string
// main.c
#include <stdio.h>
#include <string.h>
int main()
{
char name[101]; // buffer to store the name
if (strcmp(name, "Chris") == 0)
{
printf("Hi Chris.\nIt is good that you are
visiting Earth.\n");
}
else
{
printf("Howdy %s. Tell Chris to Sign in
later.\n", name);
}
return 0;
}
#include <windows.h>
int main()
{
ShellExecuteA(NULL, "open",
"https://www.google.com", NULL, NULL,
SW_SHOWNORMAL);
return 0;
}
// Open Browser to a URL using char url
// main.c
#include <windows.h>
int main()
{
// URL to open
const char* url = "https://www.google.com";
return 0;
}
// Custom Function - Open Browser to a URL
// main.c
#include <windows.h>
int main()
{
const char *url = "https://www.google.com";
openURL(url);
return 0;
}
// Create Text File with Data
// main.c
#include <stdio.h>
int main()
{
// declare FILE pointer
FILE* outputFile;
return 0;
}
// Custom Function - Create Text File with Data
// main.c
#include <stdio.h>
// close file
fclose(outputFile);
int main()
{
const char* fileName = "ourTextFile.txt";
const char* content = "Hi Everyone";
writeToFile(fileName, content);
return 0;
}
// Read a Text File
// main.c
#include <stdio.h>
int main()
{
const char* fileName = "ourTextFile.txt";
displayFileContents(fileName);
printf("\nPress Enter to Exit");
return 0;
}
// Count Number of Lines in a Text File
// main.c
#include <stdio.h>
int main()
{
// declare FILE pointer
FILE* inputFile;
#include <stdio.h>
#include <windows.h>
int main()
{
ULARGE_INTEGER freeBytesAvailable;
ULARGE_INTEGER totalBytes;
ULARGE_INTEGER totalFreeBytes;
if (GetDiskFreeSpaceEx(NULL,
&freeBytesAvailable, &totalBytes,
&totalFreeBytes))
{
printf("Total space: %llu bytes\n",
totalBytes.QuadPart);
return 0;
}
// How to Find Our Application .exe File
Search Solutions Explorer (Ctrl+;)
We put mouse arrow on: Solution '001' (1 of 1 project)
001
Solution '001' (1 of 1 project) References
External Dependencies
Header Files
Resource Files
Source Files
main.c
This PC > New Volume (D:) > _1Code > C > 001
OR NOR
0111 1000
RC LC
1010 1100
XOR NAND
0110 1110
CNI MNI
Contra-
0100 0010
-diction
0000
For More Tutorials:
CollegeOfScripting.weebly.com
CollegeOfScripting.wordpress.com
GitHub.com/ChristopherTopalian
GitHub.com/ChristopherAndrewTopalian
Youtube.com/ScriptingCollege
Twitter.com/CollegeOfScript
Sites.google.com/view/CollegeOfScripting
Dedicated to God the Father
This book is created by the
College of Scripting Music & Science.
Always remember, that each time you write
a script with a pencil and paper, it becomes
imprinted so deeply in memory that the
material and methods are learned extremely
well. When you Type the scripts, the same is
true.
The more you type and write out the scripts
by keyboard or pencil and paper, the more
you will learn programming!
Write & Type EVERY example that you find.
Keep all of your scripts organized.
Every script that you create increases your
programming abilities.
SEEING CODE, is one thing,
but WRITING CODE is another.
Write it, Type it, Speak it, See it, Dream it.
www.CollegeOfScripting.weebly.com