EECS2031 Software Tools

2016-09-12 14:44:06

[专业笔记 | Academic] , , ,

This course introduces very very fundamental C/shell programming skills on linux.

We are using C89 standard in this  EECS 2031 course. That means you cannot declare the iterator variable in a for loop. And you should be very careful when you are trying to copy any C code from Google or Stack Overflow. Because those code fragments might be written in C with C99 standard or Cpp. Professor is very nice but TAs are not that efficient. We have to wait a long time for the grading.

The course title is "Software Tools". The most difficult thing is you do not even have a "tool" in this course to write your code. You have to figure out which tools to use. I would recommend the gedit in the lab. And Makefile is also a very good tool. In your PC or laptop, you can use whatever you want, but to be noticed that XCode is using C99 standard and your computer might have other compilers.

 

September 12
LAS 2004

New yuan
Professor UT
email: utn ### cse.yorku.ca (在邮件的开头写上  EECS 2031 - )
2003在多大毕业;2002年开始在YorkU教学;多次担任这门课的教学任务,network、wireless、IT security 相关的领域,研究生相关方面可以联系这位教授

课本使用 C Programming language

Practise UNIX 方面那本书可以去图书馆借来看看

lab test 的lab才算分,别的lab可以上传script提供给lab test 使用,所用的lab都使用lab test environment

无垃圾回收

No String

EOF is equal to -1

In C, Pass-by-reference is simulated by passing the address of a variable (a pointer) and dereferencing that address within the function to read or write the actual variable. This will be referred to as "C style pass-by-reference."

source http://www-cs-students.stanford.edu/~sjac/c-to-cpp-info/references

 


September 19

c language types

变量的命名方式

  • lowercase for variable names
  • uppercase for symbolic constants

 

  • signed / unsigned (default, machine depends)
  • unsigned int: suffixed by U or u
  • long int: suffixed by L or l
  • octal number: starts with 0(zero)
  • hexadecimal: starts with 0x or 0X

 

limits.h / float.h

关于宏函数  #define ,可能会遇到这里所描述的一些坑。值得注意的是,宏函数事实上采用字符串替换方式,因此注意嵌入后的优先级。自身引用(含交叉引用)只能进行一次,不能递归。#后面的字符串会直接被转义。

 

 


September 29

operations, pointer, array

 

&(Ampersand)the address of (跟着
*(Asterisk)the value of ( 跟着pointer

pointer 的大小都是一样的,是基于电脑是 32-bit 还是 64-bit

不同类型的pointer可以相互赋值嘛?不能,必须force cast

 


October 3

pointers, bitwise operations

 

指针的++ 代表地址的++ 而已

do not use [] only use pointer to operate with the array!

array pass to function

  • passed by value
  • passed by reference

In C, it is pass by reference, therefore the method has direct access to all the elements 当然这里有更加简洁的方法

int strlen(char *s){
  int n;
  for (n = 0; *s != '\0', s++){
    n++;
  }
  return n;
}

 

Try all these

  • malloc()
  • calloc()
  • realloc()

 

 


October 17

Oct31 3:55pm期中考试

Assignment should put comment, but for lab test, no comments.

If the question does not clarify the input, we need to check this.

 

Specification is not clear. Need to catch the errors.

 

In Assignment 1 problem 2: check

  • user may remove empty list
  • user may enter -1
  • system run out memory
  • remember to free space

 

struct keyword 特性

  • struct 不能直接赋值,只能一个一个将内容物赋值(c99好像可以了,但是以学校电脑的c98标准为准)
  • struct名 和 变量名 可以重名
  • struct 可以嵌套 struct
  • struct name 整体,应该算是一个variable type

C is passed by values

句号的优先级比星号高,注意括号

(*pp).x 等同于  pp->x

Lab test including today's lecture

written need to write command in paper

4 bytes alignment when you are declare a new structure,不适用于char *连接的字符串。

 

 


October 24

注意-> * 之类的优先级

 

pointer - linked list 常见错误

  • Overruns and underruns
  • uninitialized pointers
  • null pointer de-referencing
  • memory leaks
  • Inappropriate use of freed memory
  • Inappropriately freed memory

 

使用注意

  • alloc() 的时候注意检查返回的是不是一个有效的pointer还是null
  • pointer 变量 使用完成的时候,应该free,不应该直接创建新的pointer覆盖在上面

 

pointer 和 array char搭配的时候,会导致第一个element不能获取 (待验证)

注意,定义的不一样

  • char *p[3] 与 char *(p[3])等价,意思为 char *[5],优先array  :    a array has five char pointers
  • int (*p)[3],意思为char (*)[5],优先pointer : a pointer pointed to a char array which length is five

 

 

 


November 7

bash command

 

ls lab* > myfilelist.txt
#将文件开头为lab文件列表保存为myfilelist.txt


wc 
#数文件中的行数line(-l)、单词数words(-w)、字符数characters(-c)
wc < lab3.c
wc lab3.c
#是一样的

# 通配符  ? * []


#我们还需要记忆一下
#ls cp mv rm 
#touch 
#pwd mkdir rmdir cd
#chmod chown chgrp


find 地址 -name "文件名"
find . -name "lab.c"
#在当前目录寻找lab.c
find ~ -name "lab.c"
#在home目录寻找lab.c


echo 'this is a '"test."
echo this is a test
# 这是一致的

echo a \t b
# 输出 a t b
echo 'a \t b'
# 输出 a    b

#没有在括号内的东西不会被转义

grep 参数 匹配 文件 
#参数
#  -i 大小写不敏感
#  -v 不包含
#匹配其实就是 正则表达式


sort
#列可以用空格空开
#参数
# -r反序 -n数字 -nr数字反排序 -f字符大小写敏感
# -k 2 第二列


cmp 文件1 文件2
#只是粗略大概的
diff 文件1 文件2 
#详细的信息

who | more
#将who管道到more
# a | b 是将a的输出管道通向b

sleep 2m
ps a | grep 'sleep'


 

Software engineering disasters(这个会在期末考试)

  • AT&T lines go dead
  • Mariner Rocket was Destroyed
  • Hartford Coliseum Collapse

 

 

 


November 14

bash command

 

date; who
#分号可以将两句命令放在一起

#注意 
date; who | wc -l
#还有 
(date; who) | wc -l
#的区别,分号会隔开pipe 的输入,前者

tee
#tee可以输出到screen的同时输出到文件,其实是 一个“三向”的管道

echo \*
echo '*'
echo "*"
# 双引号不保护 $ \ `` 需要注意

echo `date`
#可以输出具体日期,可以执行具体命令,要是在双引号中输出单反引号,需要将这个字符串分开例如
echo  "something `date`" '`date`'

 

linux的权限

  • u - user
  • g - group
  • a - all the user world

10bit权限机制

  • d 是否为目录
  • rwx  for u
  • rwx for g
  • rwx for a

x permission to execute or in the case of a directory, search it

 

 

Go back to file access in C

File Access in C

FILE pointer in C
fopen(char * name, char *mode) 返回 FILE *

mode 的方式

  • r - read
  • w - write
  • a - append

读写函数

  • getc()
  • putc()
  • fscanf()
  • prints()

 

Go back to file access in C

File Access in C

This course focus on sh only (sh -> bash)

#!/bin/sh

 

unix user variables

  • no space around
  • all values store in string

 

 

 

 


November 21

bash script

 

whoami
#显示当前用户名

mydater=`date`
myquotear='somestring, $mydater'
#将会是  somestring, $mydater

myquotear="somestring, $mydater"
#将会是  somestring, 今天的日期


#read user input
#用法:read 变量名

read varname
echo $varname

echo -n $varname
#stay on the same line

#read 可以同时读入多个字符串
read string1 string2 string3
#最后多出来的会放在最后一个变量中






#command line arguments (positional parameters)
#$1-$9 文件名本身是$0
#如果有多于10的参数需要shift方式获取, 每次shift一个位置
shift
#  \$  混合的情况需要注意
echo \$1
echo '\$1'
echo "\$1"

echo Number of the arguments: $#
echo All the arguments are: $*

#分页
tail file.txt
head file.txt
more file.txt


#if then else
if condition
then
   commands
elif condition_2
then
   commands
else
   commands
fi


#比对变量
if test $string1 = $string2
then
   echo match
else
   echo no-match
fi


test $var1 -eq $var2
test $var1 -eq $var2
test $var1 -eq $var2
test $var1 -eq $var2
#有很多测试的参数,需要检查Slide!!!!!!!


#for
for variable in list
do
    commands
done


#while
while read byline
do
    echo "$byline"
done
#逐行输入。。。。

#从$1的文件中读入
while read byline
do
    echo "$byline"
done < $1

#expr
sum=`expr $1 + $2`
echo $sum

sed 's/检索的正则表达式/替换字符/g'



 

 


November 28

bash script

 

count=1
argc=$#
while test $count -le $argc
do
    echo "Argument $count is: $1"
    count=`expr $count + 1`
    
    #注意 shift会影响$#, $#会减少
    shift
done

#until 
until test $item = "all"
do
   echo -n "Enter grocery item"
   read item
   echo $item >> $1
done



#case
case variable in
pattern1) command;;
partten2) command;;
*) command;;
esac


echo    获取当前进程的PID

echo $?
# $? 返回上一个命令是否成功

sh -v file
sh -x file
sh -n file

set `command`
#command 里面的东西会覆盖到  $* 作为程序的argument
env 
# 会设置整个系统的环境(环境通常采用大写,程序本身的采用小写)


function_name()
{
   commands
}







 


 

 


December 5

bash script/ C structure

 

set

break

continue

 

当包含在双引号的时候

  • "$@" is separate string
  • "$*" is in single string

 

 

C Structure

extern variable  的运用

extern int myVariable; //连接到别的文件名为myVariable 的变量名

 

static variable 的运用

注意与java不一样!

static int myNumber;//只能在当前Scope使用,退出当前scope的时候

 

register variable 的运用

register 是更加快的内存空间

有可能数量不够用,不能够活动它的地址。

 

Initialization

external static to 0

other will be garbage

在括号中字符的转换。。。

for variable in $1/*

 

这篇博文发表在 专业笔记 | Academic 目录下,标签为 , , ,
如需引用,请使用链接:https://note.mc256.dev/?p=1276

This article published in 专业笔记 | Academic with tags , , , .
Cite this page using this link:https://note.mc256.dev/?p=1276

您的邮箱地址不会被公开,评论使用Gravatar头像。
Your email address will not be published. This blog is using Gravatar.

正在提交评论... Submitting ...
正在为您准备评论控件 Loading Comment Plugin
Copyright © 2013-2024 mc256. All Rights Reserved.
Powered by WordPress on top of a dual-stack k3s Cluster using JuiceFS.
Wordpress Theme Designed By mc256.
Encrypted By Let's Encrypt.  Hosted On Linode + OVH + AWS.
DNS Provided By Hostker.
Status Page by CloudFlare Worker.