======Part 1======
=====Entries=====
====Entry 1: August 28, 2012====
Today I began reading on good old wikipedia about the different compilers I could choose from, I found the following options.
- Ch - compatible on virtually all platforms is open source. Ch also has an Integrated Development Environment for 'improved' workflow.
- GCC - What I've familiarized myself with and will most likely be using most this semester.
- Icc - A compiler thats source is open for non-commercial use. Icc has a windows only IDE, which is no help to me...
- PGCC - Part of visual studio on windows.
====Entry 2: September 25, 2012====
Impressions of Freeswitch
From what I've read about FreeSWITCH is that it's relatively new (as of 2006) and is a softswitch communicator that interfaces with both physical and digital phones. It's built on open source technologies like SQLight and Apache. FreeSWITCH accepts an array of protocols such as VOIP, SIP, Google Talk and many more to interface with and supports a wide array of audio codecs.
Here are some of the more important configuration file fore FreeSWITCH:
On our datacom server, FreeSWITCH is located in '/usr/local/freeswitch' and includes the following directories in its base:
[root@dhcp-171 freeswitch]# ls
bin conf db grammar htdocs include lib log mod recordings run scripts sounds storage
[root@dhcp-171 freeswitch]#
Bin holds the various executables that are the core of freeswitch, conf holds configuration files that some genius wrote in xml to sort in some ridiculous hierarchical model.
There are other meta items like FreeSWITCH's library and scripts.
====Entry 3: August Day, 2012====
This is a sample format for a dated entry. Please substitute the actual date for "Month Day, Year", and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
* What action or concept of significance, as related to the course, did you experience on this date?
* Why was this significant?
* What concepts are you dealing with that may not make perfect sense?
* What challenges are you facing with respect to the course?
Remember that 4 is just the minimum number of entries. Feel free to have more.
====Entry 4: August Day, 2012====
This is a sample format for a dated entry. Please substitute the actual date for "Month Day, Year", and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
* What action or concept of significance, as related to the course, did you experience on this date?
* Why was this significant?
* What concepts are you dealing with that may not make perfect sense?
* What challenges are you facing with respect to the course?
Remember that 4 is just the minimum number of entries. Feel free to have more.
=====Keywords=====
{{page>cprogpart1&nofooter}}
{{page>datacommpart1&nofooter}}
=====Experiment 1=====
====Question====
Can you include the main() of a program in a header file?
====Resources====
[[http://gcc.gnu.org/onlinedocs/cpp/Header-Files.html]]
====Hypothesis====
I suspect that you can include any function within a header file and call it. Including main().
Then call it like so:
main();
====Experiment====
I'm going to take the main portion of the encipher program from project two and place it into main.h
int main(int argc, char **argv)
{
printf("Greetings, Agent Haas.\n");
FILE *in, *out;
int cipher;
int key;
in = fopen("plain.txt", "r");
out = fopen("enciphered.txt", "w");
if(argv[1] == NULL)
{
printf("\nNo argument provided, execute with key argument.\nexample: ./encipher 1\n");
exit(1);
}
char *plain;
plain = (char*) malloc (sizeof(char) * 127);
int count = 0;
if(in == NULL)
{
printf("\nFile empty, enter some text to encipher\n");
fgets(plain, 127, stdin);
while(plain[count] != '\0')
{
count = count+1;
}
int cipher = atoi(argv[1]);
count = 0;
while(plain[count] != '\0')
{
key = 1;
if(plain[count] >= 65 && plain[count] <= 90)
{
key = plain[count] + cipher;
while(key > 90)
{
key = key - 26;
}
}
if(plain[count] >= 97 && plain[count] <= 122)
{
key = plain[count] + cipher;
while(key > 122)
{
key = key - 26;
}
}
if(key == 1)
{
key = 32;
}
fprintf(out, "%c", key);
count = count+1;
}
printf("\nEnciphered text is loated in enciphered.txt\n");
printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
}
else
{
fgets(plain, 127, in);
printf("\nText before cipherication: ");
while(plain[count] != '\0')
{
printf("%c", plain[count]);
count = count+1;
}
int cipher = atoi(argv[1]);
count = 0;
printf("\nCiphered text output: ");
while(plain[count] != '\0')
{
key = 1;
if(plain[count] >= 65 && plain[count] <= 90)
{
key = plain[count] + cipher;
while(key > 90)
{
key = key - 26;
}
}
if(plain[count] >= 97 && plain[count] <= 122)
{
key = plain[count] + cipher;
while(key > 122)
{
key = key - 26;
}
}
if(key == 1)
{
key = 32;
}
printf("%c", key);
fprintf(out, "%c", key);
count = count+1;
}
fclose(in);
fclose(out);
return (0);
}
}
====Data====
Here's main.h:
#ifndef _MAIN_H
#define _MAIN_H
int main(int argc, char **argv)
{
int t;
t = clock();
printf("Greetings, Agent Haas.\n");
FILE *in, *out;
int cipher;
int key;
in = fopen("plain.txt", "r");
out = fopen("enciphered.txt", "w");
if(argv[1] == NULL)
{
printf("\nNo argument provided, execute with key argument.\nexample: ./encipher 1\n");
exit(1);
}
char *plain;
plain = (char*) malloc (sizeof(char) * 127);
int count = 0;
if(in == NULL)
{
printf("\nFile empty, enter some text to encipher\n");
fgets(plain, 127, stdin);
while(plain[count] != '\0')
{
count = count+1;
}
int cipher = atoi(argv[1]);
count = 0;
while(plain[count] != '\0')
{
key = 1;
if(plain[count] >= 65 && plain[count] <= 90)
{
key = plain[count] + cipher;
while(key > 90)
{
key = key - 26;
}
}
if(plain[count] >= 97 && plain[count] <= 122)
{
key = plain[count] + cipher;
while(key > 122)
{
key = key - 26;
}
}
if(key == 1)
{
key = 32;
}
fprintf(out, "%c", key);
count = count+1;
}
printf("\nEnciphered text is loated in enciphered.txt\n");
printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
}
else
{
fgets(plain, 127, in);
printf("\nText before cipherication: ");
while(plain[count] != '\0')
{
printf("%c", plain[count]);
count = count+1;
}
int cipher = atoi(argv[1]);
count = 0;
printf("\nCiphered text output: ");
while(plain[count] != '\0')
{
key = 1;
if(plain[count] >= 65 && plain[count] <= 90)
{
key = plain[count] + cipher;
while(key > 90)
{
key = key - 26;
}
}
if(plain[count] >= 97 && plain[count] <= 122)
{
key = plain[count] + cipher;
while(key > 122)
{
key = key - 26;
}
}
if(key == 1)
{
key = 32;
}
printf("%c", key);
fprintf(out, "%c", key);
count = count+1;
}
printf("\nEnciphered text is located in enciphered.txt\n\n");
printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
fclose(in);
fclose(out);
return (0);
}
}
#endif
Here's the modified program:
#include
#include
#include
#include "main.h"
main();
And the gcc output:
lab46:~/src/cprog/cipher$ gcc encipher.c -o encipher
encipher.c:20: warning: data definition has no type or storage class
lab46:~/src/cprog/cipher$
Got a warning, but it worked.
====Analysis====
Based on the data collected:
* My hypothesis was indeed correct.
* My hypothesis halfway applicable, I have to explore the repercussions of the error.
====Conclusions====
Header files are a brilliant way to break up ANY function in a program to allow more readable code and FAR better organization.