On january 25 I experienced compressing and uncompressing files using gzip and gunzip. Gzip and gunzip are utilities you can use to allow for easy compressing of files and extracting of files. First gzip is used for compressing files. This utility works by opening up a command prompt and typing gzip(space)filesname.txt then press enter. This just compressed your file. To check to see if it is compressed type ls command on a command prompt and you will see filename.txt.“gz” meaning it was compressed with gzip utility. Now to unzip the compressed file type gunzip filename.txt and it will uncompressed to the current directory you are in. To check this issue ls command and see that your file does not have .gz after it. This is one way of easy compression and extracting files which is very useful utility to know.
chmod is a utility that allows you to change permissions on a file. My reason for writing about this utility is because changing permissions via the symbolic way is messy. When using chmod to change the permission you first need to understand a few things. First there are different permissions and they are: User (u) the user that owns the file, group (g) which is the group that owns the file and then other (o) which is everyone else on the system. Each of these has the read ® write (w) and execute/search(x) permission attached to each. An example would be rwxr-xr-x to rmatsch the answer.txt file. The first three letters correspond to the permission of the owner of the file then the next three are the permissions for group and then three more for other. Notice how there is a dash where a letter would be. This is because that particular group, owner,or other does not have that privilege. Also access to rwx for owner means access of (7). r-x means group access (5) and –x means other has access (1). This calculation is done by attributing the value 4 for read, 2 for write, and 1 for execute/search. If you add rwx you get (7). I should also mention the reason for 0-7 is because this is assigning of permissions by octal. For example, to assign read/ write/ execute permission for owner, read/execute for group and execute for other or commonly known as the “world” you would type in at the command prompt chmod 751 the answer.txt which would change the permission to the example listed above. The significant using octal for changing permission of files is because it takes longer changing files via symbolic notation, saving time and in the business world money. Changing permission via symbolic example: “Chmod o+rwx filename.txt” just sets other(o) to full permission read write and execute. A simple command such as “chmod 644 filename.txt” sets all three very quickly and less error is likly while typing.
root | home | rmatsch | ___________________________ | | | | | bin src file.c lab2 hello.c | __________ | | | cprog unix submit | |____________________ | | | Contact.info var2.c array.c
To access unconventional names there is three basic things to remember. When looking up files named unconventionally is not very fun thankfully you can use three characters to help with this. the characters are *,\, and ” ”. if given the file *?? ghty.file normal cat utility would when run on this would cat *?? And then cat ghty.file separately but if you were to type cat *??* you would be able to access the content. Another way use the \ to escape the following character so you would type cat *??\(space)ghty.file and then hit enter. Finally another quick and easy way is to use ” ”. This looks like this cat “*?? ghty.file” and then you can access the content.
* \ ” ” or ' '
Standard I/O (STDIO, STDOUT, STDERR)
■ Header Files (Local and System), C Standard Library (Libc), Libraries……X
■ arithmetic (equations, operators)…..X
■ logic and operators (and, or, not, xor)
■ Variables (types, ranges, sizes)…..X
■ Scope (Block, Local, Global, File)
■ Pointers (address of, assignment, dereferencing)…..X
■ Type Casting
■ Selection Structures (if, case/switch)……X
■ Repetition/Iteration Structures (for, while, do while)….X
■ Arrays (standard notation, pointer arithmetic, single-dimensional, multi-dimensional)…..X
■ File Access (Read, Write, Append)…..X
■ Structures (Declaration, Accessing Elements, Pointers to)
■ typedef, enum, union
■ Functions, Parameters (Pass by: Value, Address, Reference), Return Types, Recursion, Command-line arguments
■ Compiler, Preprocessor, Flags, Assembler, Linker, Multi-file programs (how to structure, how to compile)
■ I/O Streams (cin, cout, cerr, stream operators) [C++]
■ Namespaces [C++]
■ Type Casting Operators, Const-Volatility Specifiers (const, volatile) [C++]
■ Classes (Objects, Constructor, Destructor, Access Control, Public, Protected, Private, Friend, “this” pointer) [C++]
■ Inheritance (single, multiple Inheritance), Polymorphism/Virtual Functions, Abstract Base Class [C++]
■ Overloading (Functions, Operators) [C++]
■ Exception Handing (throw, try, catch) [C++]
■ Templates, STL (Standard Template Library) [C++]
Variables are storage containers which can be permanent but most of the time they vary or change throught a computer program.
Variables have 3 basic properties.First is name, in order to use a variable you must have declare a name for the variable to call it by. secondly you must select a data type such as type “interger” or “char”. Thirdly is the size of this container you want the variable to be. Thankfully this is already determined by the data type you have established so the work is already done. The data type selected can hold a certain amount of data. Below is code for a program to show you the different sizes of a data types there ranges the unique values they can have.I must also mention that upon selection of a data type there are signed and unsigned variables also. Signed variables can handle negative along with positive values and unsigned variables can handle only positive values.
Code :
#include <stdio.h> #include <math.h> int main() { // declare variables unsigned char uc = 0; signed char sc = 0; signed short int ssi = 0; unsigned short int usi =0; signed long int sli = 0; unsigned long int uli =0; signed long long int slli = 0; unsigned long long int ulli = 0; signed int si = 0; unsigned int ui = 0; unsigned long long int quantity = 0; //display info for unsigned char data type printf("Unsigned char is %u bytes\n", sizeof(uc)); printf("The range of an unsigned char is %hhu to %hhu\n", uc, (uc-1)); quantity=(unsigned char)(uc-1) + 1;/* unsigned char -1 = 255 +1 for all unique values*/ printf("An unsigned char can store %llu unique values\n\n", quantity); //display info for signed char data type printf("Signed char is %d bytes\n", sizeof(sc)); quantity = (unsigned long long int)pow(2, (sizeof(sc)*8)); /*2 raised to the power of 8 times data type in bytes */ printf("The range of a signed char is %hhd to %hhd\n", (sc-(quantity/2)), (sc+(quantity/2)-1)); printf("A unsigned char can store %llu unique values\n\n", quantity); printf("Unsigned short int is %u bytes\n", sizeof(usi)); quantity = (unsigned long long int)pow(2, (sizeof(usi)*8)); printf("The range of a unsigned short int is %u to %llu\n", usi, ((quantity)-1)); printf("An unsigned short int can store %llu unique values\n\n", quantity); printf("Signed short int is %d bytes\n", sizeof(ssi)); quantity = (unsigned long long int)pow(2, (sizeof(ssi)*8)); printf("The range of a signed short int is %lld to %lld\n", (ssi-(quantity/2)), (ssi+(quantity/2)-1)); printf("A signed short int can store %llu unique values\n\n", quantity); printf("Signed int is %d bytes\n", sizeof(si)); quantity = (unsigned long long int)pow(2, (sizeof(si)*8)); printf("The range of a signed int is %lld to %lld\n", (si-(quantity/2)), (si+(quantity/2)-1)); printf("A signed int can store %llu unique values\n\n", quantity); printf("Unsigned int is %u bytes\n", sizeof(ui)); quantity = (unsigned long long int)pow(2, (sizeof(ui)*8)); printf("The range of a unsigned int is %llu to %llu\n", ui,((quantity)-1)); printf("An unsigned int can store %llu unique values\n\n", quantity); printf("Signed long int is %d bytes\n", sizeof(sli)); quantity = (unsigned long long int)pow(2, (sizeof(sli)*8)); printf("The range of a signed long int is %lld to %lld\n", (sli-(quantity/2)), (sli+(quantity/2)-1)); printf("A signed long int can store %llu unique values\n\n", quantity); printf("Unsigned long int is %u bytes\n", sizeof(uli)); quantity = (unsigned long long int)pow(2, (sizeof(uli)*8)); printf("The range of a unsigned long long int is %llu to %llu\n", uli,((quantity)-1)); printf("An unsigned long int can store %llu unique values\n\n", quantity); printf("Signed long long int is %d bytes\n", sizeof(slli)); quantity = (unsigned long long int)pow(2, (sizeof(slli)*8)); printf("The range of a signed long long int is %lld to %lld\n", (slli-(quantity/2)), (slli+(quantity/2)-1)); printf("A signed long long int can store %llu unique values\n\n", quantity); printf("Unsigned long long int is %u bytes\n", sizeof(ulli)); quantity = (unsigned long long int)pow(2, (sizeof(ulli)*8)); printf("The range of a unsigned long long int is %llu to %llu\n", ulli,((quantity)-1)); printf("An unsigned long long int can store %llu unique values\n\n", quantity); return(0); }
What command line looks like when program is run.
lab46:~/src/cprog$ ./project0 Unsigned char is 1 bytes The range of an unsigned char is 0 to 255 An unsigned char can store 256 unique values Signed char is 1 bytes The range of a signed char is -128 to 127 A unsigned char can store 256 unique values Unsigned short int is 2 bytes The range of a unsigned short int is 0 to 65535 An unsigned short int can store 65536 unique values Signed short int is 2 bytes The range of a signed short int is -32768 to 32767 A signed short int can store 65536 unique values Signed int is 4 bytes The range of a signed int is -2147483648 to 2147483647 A signed int can store 4294967296 unique values Unsigned int is 4 bytes The range of a unsigned int is 0 to 4294967295 An unsigned int can store 4294967296 unique values Signed long int is 8 bytes The range of a signed long int is -9223372036854775807 to 9223372036854775806 A signed long int can store 18446744073709551615 unique values Unsigned long int is 8 bytes The range of a unsigned long long int is 0 to 18446744073709551614 An unsigned long int can store 18446744073709551615 unique values Signed long long int is 8 bytes The range of a signed long long int is -9223372036854775807 to 9223372036854775806 A signed long long int can store 18446744073709551615 unique values Unsigned long long int is 8 bytes The range of a unsigned long long int is 0 to 18446744073709551614 An unsigned long long int can store 18446744073709551615 unique values
variables are seen as memory cells that can be accessed using their identifiers (aka pointers). Because we did not have to care about the physical location of our data within memory, we can simply used its identifier when we need to refer to the variable.
Below is code to help understand what pointers acually do.
#include <stdio.h> int main() { // a is initiallly set to zero int a = 0; int * b; /* b is declared as a pointer variable by star b */ b = &a; /* b is assigned the adress of a */ *b = 12; /* what ever b is pointing at is now set equal to 12 not b itself */ printf("a contains %u \n", a ); printf("a's address is 0x%x\n", &a ); printf("b contains %u \n", *b); // b contains the value stored at what b is pointing to. (the container or another variable) printf("b points to 0x%x\n", b); printf("b's addres is 0x%x\n", &b); return(0); }
lab46:~/src/cprog$ ./var2 a contains 12 a's address is 0xe5a3f33c b contains 12 b points to 0xe5a3f33c b's addres is 0xe5a3f330
+ Adding binary operator, adds two operands to get a sum, (addend +adend = sum - Subtract binary operator, inverse of adding, (minuend -subtrahend = difference) % Modulus takesremainder after an integer division ++ means +1 -- means -1 * Multiply binary operator (multiplicand times multiplier = product) / Divide binary operator(dividen / divisior = quotient)
c=5 b=3 p=5 q=5 c-b=a = 5-3=2 a =2 c+b=a = 5+3=8 a =8 c*b=a = 5*3=15 a =15 x=p/q = 5/5=1 a =1 c++ means c= to 5 plus one =6
Header files
Header Files are files that are incoporated in c code to allow you added funtionality such as use of funtions or expressions.
#include <stdio.h> #include <stdlib.h> code to demonstrate
#include <stdlib.h> #include <stdio.h> int main() { return(0); }
Arrays
Arrays can be thought of as sequentialy ordered containers. The ability to take a big piece of data such as string and break it up into individual pieces to be manipulted as needed. because arrays store data in “numbered containers” arrays are a good thing to know.
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { unsigned char i; if (argc<2) { printf("%8s must be run with 1 or \ more arguments, you only provide %hhu\n", *(argv+0),(argc-1)); exit(1); } printf("pleas enter a message to be ciphered") for(i=0;i<argc; i++) { printf("argv[%hhu]: %s \n",i,*(argv+i)); } return(0); }
./acs h e y t h i s i s a n a r r a y you ran this program with 17 arguments, they are: argv[0]: ./acs argv[1]: h argv[2]: e argv[3]: y argv[4]: t argv[5]: h argv[6]: i argv[7]: s argv[8]: i argv[9]: s argv[10]: a argv[11]: n argv[12]: a argv[13]: r argv[14]: r argv[15]: a argv[16]: y
multidemensional array would look similar to this
0 1 2 3 0 y r e d 1 a b h o 2 f k z p 3 t u m l argv[1][2]:k
Selection Structures (if, case/switch)
selection structure is a order of sequence of check statments (conditional statements) that are true or false. If the stament is true then do somthing.
if (in == NULL){ fputs("please enter a message to cipher:\n", stdout); fgets(msg, sizeof msg, stdin); fprintf(nf, "%s", msg); fclose(nf); nf = fopen("nofile.txt", "r"); letter1 = fscanf(nf,"%c", &letter); }else{ letter1 = fscanf(in, "%c", &letter); }if (key == NULL){ printf("please enter a key to encipher with :\n"); scanf("%d", &keyvalue); }else{ fscanf(key,"%d",&keyvalue);
Repetition/Iteration Structures (for, while, do while)
Repetitive/iteration structures or loops are a statement which allows code to be repeatedly executed until a condition is meet or can be instructed to “do” something while this condition is true.
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { unsigned char i; if (argc<2) { printf("%8s must be run with 1 or \ more arguments, you only provide %hhu\n", *(argv+0),(argc-1)); exit(1); } printf("you ran this program with %hhu arguments, they are:\n", argc); for(i=0;i<argc; i++)/* Condition to be checked */ { printf("argv[%hhu]: %s \n",i,*(argv+i)); } return(0); }
another example
while (letter1 != EOF) { if((letter >= 'A') && (letter <= 'Z')) letter = (((abs(letter - 65) + keyvalue)%26)+65); else if((letter >= 'a') && (letter <= 'z')) letter = (((abs(letter - 97) + keyvalue)%26)+97); fprintf(out,"%c",letter); if (in == NULL){ letter1 = fscanf(nf, "%c", &letter); }else{ letter1 = fscanf(in, "%c", &letter); }
File access
File Access is when you read from, write to, or append to a file. the program can read write or append to a file.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(){ char letter1=0; char msg[250]; FILE *in, *out, *key,*nf; char letter = 0; int keyvalue; nf = fopen("nofile.txt", "w"); in = fopen("message.txt", "r"); out = fopen("cipher.txt", "w"); key = fopen("key.txt","r"); if (in == NULL){ fputs("please enter a message to cipher:\n", stdout); fgets(msg, sizeof msg, stdin); fprintf(nf, "%s", msg); fclose(nf); nf = fopen("nofile.txt", "r"); letter1 = fscanf(nf,"%c", &letter); }else{ letter1 = fscanf(in, "%c", &letter); }if (key == NULL){ printf("please enter a key to encipher with :\n"); scanf("%d", &keyvalue); }else{ fscanf(key,"%d",&keyvalue); } while (letter1 != EOF) { if((letter >= 'A') && (letter <= 'Z')) letter = (((abs(letter - 65) + keyvalue)%26)+65); else if((letter >= 'a') && (letter <= 'z')) letter = (((abs(letter - 97) + keyvalue)%26)+97); fprintf(out,"%c",letter); if (in == NULL){ letter1 = fscanf(nf, "%c", &letter); }else{ letter1 = fscanf(in, "%c", &letter); } }if (in == NULL){ fclose(nf); }else{ fclose(in); } if (key != NULL){ fclose(key); } //fclose(in) fclose(out); //fclose(nf); return(0); }
lab46:~/src/cprog$ cat cipher.txt jpa lab46:~/src/cprog$ lab46:~/src/cprog$ cat plain.txt hey lab46:~/src/cprog$
The course objective is for students to be able to write, compile code, use pointers and variables effectively and efficiently. Also this course is designed for students to gain a basic comprehension of memory such as various data types. Also obtain valuable debugging skills and demonstrate the ability to use logic and structure to solve problems. Develop solutions shown in c++ program language.
To measure successful academic/intellectual achievement of this objective. students should be given a final project that incorporates various lessons learned through the course because an important part of intellectual achievement is applying what you leaned. Students should also be asked to write various programs on the spot and should be completed given sufficient time.
Correctness - are things displayed when they are supposed to, were variables initialized etc. Design/efficiency- there is many ways to design a program but there may be better ways or more efficient ways. (Are the right size variables used?)
Logic- has a basic concept of logic (uses loop instead of 100 if statements) Other- Does the program do what it was designed to do and accurately.
Reflecting upon my results of the measurement to ascertain achievement of the course objective.
* How did you do? I did not do to bad but still have a lot to learn. * Is there room for improvement?yes * Could the measurement process be enhanced to be more effective? Yes * Do you think this enhancement would be efficient to employ? Yes * Could the course objective be altered to be more applicable? No
Reflecting on the measurements I did not do too bad, but of course have a lot to learn so there is much room for improvement.
Local host….X
■ Remote host……X
■ Home directory……X
■ Current working directory…..X
■ Types of files (regular, directory, special)……X
■ File manipulation…..X
■ Text Processing…..X
■ The VI editor…..X
Local host
Local host is is the standard hostname given to the address of the loopback network interface or the web address of the computer you are working on. Although local host can take different forms, the web address is simply your computer's identifier.
enter “http://127.0.0.1” into any web browser, and you will see a web page hosted by a web server on the same computer if one is running.
Remote host
Remote hosts are computers that are not locally accessed. They are further away from where you are such as servers or public internet.
a computer connected to lab46.corning-cc.edu through ssh is an example of a remote host
File Manipulation
file manipulation is the ability to control files such as moving them, removing them, copying them.
lab46:~/src/cprog lab46:~/src/cprog$ touch file123 lab46:~/src/cprog$ cp file123 file2 lab46:~/src/cprog$ rm file123 rm: remove regular empty file `file123'? y lab46:~/src/cprog$ mkdir file123 lab46:~/src/cprog$ rmdir file123 lab46:~/src/cprog$ mv file2 /tmp lab46:~/src/cprog$ lab46:~/src/cprog$ cd /tmp lab46:/tmp$ ls A.txt cformansencryption.c fishd.log.vcordes1 img--01315.htm img--93112.asc lost+found nofile.txt prog1x5 aptitude-rlott.11795:dKeQWo fbarb.txt fishd.socket.vcordes1 img--12835.htm img-file-88471.c mc-jbamper plain.txt prog1x5.c aptitude-rlott.11860:1ABldB file2 hsperfdata_brobbin4 img--39027.htm img-logout-04391.asc mc-tedmist1 prog1x4.c wierdfileiswierd lab46:/tmp$
Home directory
The home directory is your default directory. Whenever you open up a cmd prompt you are at your home directory.
root | home | rmatsch | ___________________________ | | | | | bin src file.c lab2 hello.c | __________ | | | cprog unix submit | |____________________ | | | Contact.info var2.c array.c
login as: rmatsch rmatsch@lab46.corning-cc.edu's password: __ _ _ _ __ . . . . . . . . . . . . . . . . . . . . . . . . . | | __ _| |__ / | |_/ / . Basic System Usage: Type 'usage' at prompt . | |__/ _` | '_ \\_ _/ _ \ . Events and News: Type 'news' at prompt . |_____\__,_|_.__/ |_|\___/ . Broken E-mail? Type 'fixmail' at prompt . --------------------------- . Check Lab46 Mail: Type 'alpine' at prompt . c o r n i n g - c c . e d u . . . . . . . . . . . . . . . . . . . . . . . . . Lab46 is the Computer & Information Science Department's Student Development Server for Computer-related coursework, projects, and exploration. For more information, please check out: .. . . . . . . . . . .. . Lab46 Web Page: http://lab46.corning-cc.edu/ . . Lab46 Help Form: http://lab46.corning-cc.edu/help_request . . Help E-mail: haas@corning-cc.edu or wedge@lab46.corning-cc.edu . .. . . . . . . . . . .. You have old mail. Last login: Sat Mar 3 09:06:57 2012 from user-10bj433.cable.mindspring.com lab46:~$
by typing pwd you are shown where you are at in relaton to directories. Also by typing in cd you are defaulted back to your home directory even if you are in another directory.
lab46:~$ lab46:~$ pwd /home/rmatsch lab46:~$ cd src lab46:~/src$ cd lab46:~$
Current working directory
The current working directory is the directory that you're in.
The current working directory is the directory that you are in. Typing cd command with no arguments will change your current working directory to your home directory.The pwd command reveals the current working directory.
lab46:~$ cd src/unix lab46:~/src/unix$ pwd /home/rmatsch/src/unix lab46:~/src/unix$ cd lab46:~$ pwd /home/rmatsch lab46:~$
Text Processing
Text Processing is a tool used to edit text, save text into files or from files but can also be used to change it other text files.
“nano” is a good example of a text processing.
lab46:~$ lab46:~$ nano hello.c
#include<stdio.h> int main() { printf("Hello, World !\n"); return(0); }
Types of files (regular, directory, special)
There are three basic types of files, regular files like text, directories such as a file that contains other files within, and special files which can be programs.
hello1.c is a txt file,unix is a directory that contains other files,and hello1 is a compiled c code program.
lab46:~/src$ ls Makefile cprog hello1 hello1.c submit unix lab46:~/src$ lab46:~/src$ cd unix lab46:~/src/unix$ lab46:~/src/unix$ ls arc.tar.gz cs1.txt cs3.txt cs5.txt lab1.txt lab3.txt lab5.txt contact.info cs2.txt cs4.txt lab0.txt lab2.txt lab4.txt shell lab46:~/src/unix$
Vi editor
The VI editor is a text editor with two modes one mode you can only insert, and in another mode you can only enter commands.
Demonstration of the chosen keyword.
lab46:~$ vim hello.c
#include<stdio.h> int main() { printf("Hello, World !\n"); return(0); } ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "hello.c" 7L, 76C
to write to this file i must hit the i key for insert and then insert is diplayed to show you what mode you're in.
~ -- INSERT --
to save changes go to command mode by hitting esc key and then typing :wq to quit without saving type :q!
Upon completion of this course, students should be able to show:
familiarity with the structure of UNIX systems the ability to accomplish/automate tasks exposure to command-line tools and utilities experience the connection between UNIX and C understanding of the UNIX philosophy exposure to Open Source concepts and ideals familiarity with important system concepts exposure to computer security understanding and use of pattern matching problem solving activities
The objective entails being familiar and comfortable in using unix to accomplish task. It also entails understanding basic understandings of unix.
The method i use for measuring successful academic/intellectual achievement of this objective would be to be asked to complete various task to be completted in a timly mannor for a final.
Follow your method and obtain a measurement. Document the results here.
upon reflect my achievement of the particular course objective. i would do pretty good. Although i do pretty well there still could be room for improvement but am happy with the results.The measurement process could be enhanced to be more effective if more task were asked.I also believe these enhancement would be efficient to employ.however, what is asked for the objective is fine.
What happens when you initialize a variable before the loop instead of initializing within the loop condition?
When using a loop in a program you have a condition that must be checked for the loop to start and end the loop. Usually the loop counting variable is initialized in the check condition of the loop.(common programming practice of loops)
Before actually performing the experiment I believe that it will make no difference in how the program runs as long as the variable is not used before it is needed. Declaring global variables in a program are so you can use those variables throughout and at any part in the program so this includes the loop.
I am going to test my hypothesis by developing a program which has a loop counting variable except i will initialize the variable in the start of the program instead of within the loop condition. My experiment will begin by first making a small program with initialization done within the loop condition. Then testing to make sure the program works and there are no bugs. Then I can proceed to initialize before the loop and not initialize with in the loop to see what happens.
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { unsigned char i; i=0; if (argc<2) { printf("%8s must be run with 1 or \ more arguments, you only provide %hhu\n", *(argv+0),(argc-1)); exit(1); } printf("you ran this program with %hhu arguments, they are:\n", argc); for(i<argc; i++) { printf("argv[%hhu]: %s \n",i,*(argv+i)); } return(0); }
The out come of this exsperiment for the above code did not work out. Upon analysis of why i looked closer at the loop condition parameters.The loop condition wants three parameters. this is known because when you go to **manuel for the “for loop” or type “man 3 for” in command line and get this 'For' loop
“SYNOPSIS
for start test next body
_
DESCRIPTION
For is a looping command, similar in structure to the C for statement. The start, next, and body arguments must be Tcl command strings, and test is an expression string. The for command first invokes the Tcl interpreter to execute start. Then it repeatedly evaluates test as an expression; if the result is non-zero it invokes the Tcl interpreter on body, then invokes the Tcl interpreter on next, then repeats the loop. The command terminates when test eval- uates to 0. If a continue command is invoked within body then any remaining commands in the current execution of body are skipped; processing continues by invoking the Tcl interpreter on next, then evaluating test, and so on. If a break command is invoked within body or next, then the for command will return immediately. The operation of break and continue are similar to the corresponding statements in C. For returns an empty string."
A loop condition will not look anywhere else in the program for the variables it needs. The loop expects the initialization to be done within the loop condition.(Example)for(i=0;i<argc; i++). The loop counter will not add outside of the loop and pull the info back to check it expects the variable to be initialized within the parentheses.so by my experiment i have proved my hypothesis to be incorrect and there was more involved then initially thought.
What will happend when i change *4 to *3 when allocating sizeof char when dealing with arrays.
class notes.
Based on what you've read with respect to my original posed question, i believe that in a program that is dependant on atleast 4 memory spaces when changed to 3 will cause a segmentation fault or possible incorrect results.my rayional for this is because when there is not eough space it will usually truncate but to low of memory i believ it will seg fault.
by running a program that depends on space for array and taking space out to see what will come of the program.
The prgram compiled but when running it segmentation faulted.
Based on the data collected:
What can you based on the experiment i can ascertain that by running a program with less memory then required will cause a segmentation fault.
What will happen if i use single quotes in a prinf funtion?
C ansi book
I believe you will obtain an err message when tyring to compile. the reason for my educated guess is because printf() usually prints whats is in double quotes.
my exsperiment will entail creating a program that prints a mesage to stdout with quotes and then without quotes
#include<stdio.h> int main() { printf("Hello, World !\n"); return(0); }
and the other code to run is:
#include<stdio.h> int main() { printf('Hello, World !\n'); return(0); }
lab46:~$ gcc -o hello hello.c hello.c:5:16: warning: character constant too long for its type hello.c: In function 'main': hello.c:5: warning: passing argument 1 of 'printf' makes pointer from integer without a cast /usr/include/stdio.h:339: note: expected 'const char * __restrict__' but argument is of type 'int' lab46:~$
Based on the data collected the code did compile so i was wrong but when running the program it segmentation faulted.
I was suprised it compiled at first but when giving the exsperiment more time to think i the reason for warning is because it was taking hello, world! and putting it into string so that explains warnings and segmentation fault.