======C/C++ Programming Journal======
====JAN 22, 2015====
Pre-Processor
#include
int main()
{
fprintf(stdout, "Hello, World!\n");
return(0);
}
Compile & Run
gcc -S hello.c (Compiles To Assembly)
gcc -o hello hello.c (Compiles .C file into fully executable file)
./hello (Runs the program)
==== Data Types ====
Signed char
Unsigned short
long int
long long
float
double
long double
==== STD ====
stdin
stdout
stderr
==== Tools/Debugging ====
Diff (Compares two files for differences. Returns nothing if file is an exact copy.)
ERROR Messages from compiling.
Ex:
lab46:Thu Jan 22:~/src/cprog$ gcc -o broken broken1.c
broken1.c: In function 'main':
broken1.c:4:35: error: expected ')' before ';' token
fprintf(stdout, "Hello, World!\n";
^
broken1.c:6:1: error: expected ';' before '}' token
}
^
lab46:Thu Jan 22:~/src/cprog$
====JAN 29, 2015====
#include
int main()
{
int input; //Declare a variable.
input=0; //Initialize variable. (int input=0;)
int result=0;
fprintf(stdout,"Enter A Number: ");
fscanf(stdin,"%d",&input);//Format %
result=input*36; //Calculate input*36
fprintf(stdout,"%.4d*36=%d\n",input,result);
return(0);
}
lab46:Thu Jan 29:~/src/cprog$ ./io0
Enter A Number: 9999
9999*36=359964
==== mms0.c ====
#include
#include
int main()
{
int input, fst, mod;
fprintf(stdout,"Enter a two digit number ending in five: ");
fscanf(stdin,"%d",&input);
mod=(input%5);
while (( mod != 0) && (input > 95) || (input < 15))
{
fprintf(stdout, "\noops! Number should fit this criteria.\nA ny number ending in 5 rangeing between 15-95: ");
fscanf(stdin, "%d",&input);
}
fst = ((input-5)/10)*(((input-5)/10)+1);
fprintf(stdout,"%d*%d=%d25",input,input,fst);
fprintf(stdout,"\n%d",input%5);
return(0);
}
==== mbe0.c ====
#include
#include
#include
int main()
{
int input, result, result1, result2;
fprintf(stdout, "Enter a two or three digit number to be multiplyed by 11\n");
fscanf(stdin,"%d", &input);
result=(input%10);
result1=(input/10);
result2=(result+result1);
if (result2 > 9)
{
result1=result1+(result2/10);
result2=(result2%10);
}
fprintf(stdout, "11*%d=%d%d%d\n", input, result1, result2, result);
return(0);
}
awsome.c
#include
#include
#include
int main()
{
int guess, pick, num=0, done=0;
srand(time(NULL));
pick=rand()%10+1;
do{
fprintf(stdout, "Guess a number between 1-10: ");
fscanf(stdin, "%d", &guess);
if (guess==pick)
{
fprintf(stdout, "Correct!\n");
done=1;
}
else if (guess > pick)
{
fprintf(stdout, "Guess too high\n");
}
else
{
fprintf(stdout, "Guess too low\n");
}
}while((done != 1)&&(num++<5));
// while (i>0)
// {
// }
// for (i=0; i>0; i++)
// {
// }
// do{
// }while(condition);
return(0);
}
aray.c
1 //int b[5];
2 //b[0]=12;
3 //b[1]=b[0]+a;
4 //b[c]=b[0]*2;
5 //int d[2][3];
6 //int e[2][3][2];
7 //[][][][][]
==== Feb/26/2015 ====
#include
#include
int main(int argc, char **argv)
{
int i;
fprintf(stdout,"%s was called with %d arguments. They are: \n", argv[0],argc);
for(i=0; i
#include
#include
int main()
{
char *b;
char size;
size=sizeof(char*);
fprintf(stdout,"\n%d\n%d",size,b);
return(0);
}
==== March/05/15 ====
#include
#include
char *allthezeros(char);
char howbigthastring(char *);
char howbigthastringwithmax(char *, char);
void showmethenumber(char *, char);
int main(int argc, char **argv)
{
int i;
char *number;
if (argc < 1)
{
fprintf(stderr, "Error! Not enough arguments!\n");
exit (1);
}
else if (argc > 1)
{
fprintf(stderr, "Error! Too many arguments!\n");
exit (2);
}
number = allthezeros(8);
for(i = 0; i < i < 8;)
number[i] = *(*(argv+1)+i);
i++;
}
showmethenumber(number, howbigthastring(number));
return(0);
}
char *allthezeros(char len)
{
char *data;
//char data[];
int i;
data = (char *) malloc (sizeof(char) * len);
for (i = 0; i < len; i++)
{
//data[i] = 0;
*(data+i) = 0;
}
return(data);
}
char howbigthastring(char *thearray)
{
char i = 0;
while(*(thearray+1) == '\0')
{
i++;
}
}
void showmethenumber(char *stuff, char longness)
{
char i;
for (i = 0; i < longness; i++)
{
fputc(*(stuff+i), stdout);
fputc('\n',stdout);
}
}
**rectangle**
#include
#include
class rectangle{
public:
rectangle(); //constructor
rectangle(int,int);
int area();
int perimeter();
int getLength();
void setLength(int);
int getWidth();
void setWidth(int);
private:
int length;
int width;
};
rectangle::rectangle(){
length=0;
width=0;
}
rectangle::rectangle(int length, int width){
this->length=length;
this->width=width;
}
int rectangle::area(){
return(length*width);
}
int rectangle::perimeter(){
return(2*length+2*width);
}
int rectangle::getLength(){
return(length);
}
void rectangle::setLength(int length){
this->length=length;
}
int rectangle::getWidth(){
return(width);
}
void rectangle::setWidth(int width){
this->width=width;
}
int main()
{
rectangle r1, *r2;
r2 = new rectangle(4,7);
r1.setLength(9);
r1.setWidth(11);
r2->setWidth(8);
fprintf(stdout,"r1 length is %d\n",r1.getLength());
fprintf(stdout,"r1 width is %d\n",r1.getWidth());
fprintf(stdout,"r1 area is %d\n",r1.area());
fprintf(stdout,"r1 perimeter %d\n",r1.perimeter());
printf("\n");
fprintf(stdout,"r2 length is %d\n",r2->getLength());
fprintf(stdout,"r2 width is %d\n",r2->getWidth());
fprintf(stdout,"r2 area is %d\n",r2->area());
fprintf(stdout,"r2 perimeter %d\n",r2->perimeter());
return(0);
}
**Classes**
Cprog~ April 09, 2015
C++ -classes/objects
#include | #include
#include | #include
g++ .cc, .c++, .cpp, .C
public, protected, private
======HPC Fundamentals Journal======
====JAN 22, 2015====
===== Bios Menu =====
==== System Info ====
Model number, Service Tag(Manufacturer support)
Bios Version (2.4.1)
Clock Speed- Rate at which the processor can handle/process a given set of instructions.
Cores- CPU's Capability to handle multi-tasking or multiple instructions.
SATA Ports- Hard Drives, CD/DVD Drives (0-4)
==== Lair Proxy ====
http://10.80.2.3:3142/
====JAN 27, 2015====
===== LFS =====
Linux from scratch!
This will be an ongoing project.
I have collected various resources for this endeavor. For now I present today's notes along with some ideas/theories and steps.
System D? or Traditional Linux?
==== Partitioning space for LFS ====
cfdisk, fdisk, mkfs
I had created a 10.00GB partition on the left over space of the host computer's hard drive using cfdisk.
The partition file can be found in /dev.
The partition was then set to use the current ext4 file system using mkfs.
I would then prepare to mount the newly partitioned space to /mnt where from there an environment variable would be created to point to the mounted partition /mnt/LFS.
export LFS=/mnt/lfs
Enabling the use of $LFS
====JAN 29, 2015====
==== Package Management ====
Notes:
MD5SUM-Checks, Data authentication detects changes in files that could cause errors using cartographic hashes (128 bit)
SHA-256, WhirlPool, Ubuntu Hashes PGP Signature
==== Package Info ====
**ACL**(Access Control List)
"Which users or system processes are granted access to objects, as well as what operations are allowed on a given object."
**ATTR**(Attribute)
"Extended attributes are name: value pairs associated permanently with files and directories, similar to the environment strings associated with a process."
**AUTOCONF**(AUTO Configure)
"Extensible Package of M4 macros. Produce shell scripts to automatically configure software source code packages. Creates a configuration script for a package from a template file that lists the OS's features that the package can use."
Automake, Bash, BC, Binutils, Bison, Bzip, Check, Coreutils, D-Bus, Deja-GNU, Diffutils,E2fsprogs, Expat, Expact, File, Finutils, Flex, Gawk, GCC, GDBM, Gettext, Glibc, GMP, Gperf, Grep, Graff, Grub, Gzip, Lana-ETC, Inetutils, Intiital, IProute2, KBD, Kmod, Less, Libcap, Libpipeline, Libtool Linux, M4, Make, ManDB, Man Pages, MPC, MPFN, NCurses, Patch, Tar, TC1, Textinfo, Time Zone Data, Util-Linux, VIM, XML, XZwtil, Xlib
(There may be some typos here.)
==== Create Group & USER ====
**groupadd** (name of group)
**useradd -s**(choose default user shell) **/bin/bash -g** (add user to lfs) **lfs -m** (creates a home directory for lfs) **-k /dev/null** (prevents copying of files from a skeleton directory)
**chown -v lfs** (make user owner of directory)
**su - lfs** (substitute or switch user)
==== SBU ====
Standard build/compile time for source packages.
==== Test Suites ====
Check or test for proper compilation.
==== Build & Compilations ====
=== Binutils ====
Info: Binutils (Binary Utilities) provides a lot of linking to assembly source, object files and profile data. The basis for managing and creating "binary" programs.
First pass of binutils successfully completed. (note. Don't delete the lfs home directory)
Used the make command to build binutils. Then make install for installation.
=== GCC ===
GNU Compiler collection.
"The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, Ada, and Go, as well as libraries for these languages (libstdc++, libgcj,...). GCC was originally written as the compiler for the GNU operating system. The GNU system was developed to be 100% free software, free in the sense that it respects the user's freedom."
[[https://gcc.gnu.org/|https://gcc.gnu.org/]]
=== Compile/Install Glibc & Linux API headers ===
Glibc: Provides the standard c library for the kernel.
Linux API Headers: The kernel itself and modifications to header files(.h) that may be out of date or incompatible?
==== Chapter 6 ====
The remaining installation will be done in the chroot of the mini linux system.
NODES:Directories are tables that map directories and files to iNodes.
Names of a directory or files are stored in a separate inode. (The name inode map)
Creating Essential File-system and Symlinks:
The operating system needs to mount a virtual file-system for proper communication with the kernel.
Localedef: The following instructions will install the minimum set of locales necessary for the optimal coverage of tests.