المدونة

C tutorial

i know i’am not writing a lot on this page and that’s sucks but
forgive me i’am a student i have to study a little bit and program
let’s come up with a new thing which is
writing a hello world program in c
here is the complete code:
#include
main(){
printf(“Hello,World”);
}
it’s pretty easy right let’s explain this code
#include
well we include here(equal to import in python)the library called
standard input output for the usage of the function printf() below
which prints something to the screen
main()
this is the main function which is executed and it has to be there in
the c code
well can i make other functions myself in c?
yes but you have to run it inside of main() between the ()
we write the arguments that will be given to the function(i will
explain more when we get to functions)
well {} the two braces this is the where the code get executed by
the main function
printf(“Hello,World”);
well here we print to screen Hello World
what is the “” it is something called a string which is written
between “”(double quotes) or ”(single quotes) this is a data type in
c the string can be any character a number a letter even the
space that i wrote is considered a character in string
well this the hello world program

مقالة أولى على المدونة

Python Programming

okay if you are a python beginner
what is python?
python is a programming language.Python is a powerful
programming language i am going to be getting to how to

download and install python
you can download it from this page
Here
you will find in this link both of python 2.7.12 and 3.5.2
what is the difference between python 2 and 3 ?
2 differs from 3 in the syntax and the modules but they are very similar in formal you can choose from them
okay once you have installed python
what are modules ?
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__.
you can find more about modules from this page:
https://docs.python.org/2/tutorial/modules.html
type this code:
import math
math.sqrt(4)
from math import sqrt
sqrt(4)
the difference between the two import statments import math and
from math import sqrt that you get to use math above but when
you use a specific function in math you have to math.functionname
because the function belongs to math but if you imported the
function like this from module import function
you defined the function to python
maybe you have seen “C://” “E://” this is a beginning of path
well what is a path?
a path is like a way to a place in the system like a (file or a folder)
how can i know the path ?
you can do it by clicking the (file or folder) with a right click and clicking properties you will see the location
this is the path the location of the (file or folder) in the system
this is some paths of some files:
C:\Users\yossef\Desktop\newfolder
E:\mstn.htm
you can specify the path like this
(the name of the local disk)\(the name of the folder)\(followed by the file in the folder)

what is a directory?
a directory is the place where the path refers to like a folder but not an app
C:\Users\yossef\Desktop this is a directory
C:\Users\yossef\Desktop\t t is a (file or a folder in the directory
which is the Desktop)
okay let’s get into some code:
from os import listdir,rename,mkdir,rmdir,chdir,getcwd,system,walk # i will be talking about this 6 functions in the os module
listdir(“C://”) # if you typed this on your machine you will get this result:
[‘$Recycle.Bin’, ‘autoexec.bat’, ‘config.sys’, ‘Documents and Settings’, ‘hiberfil.sys’, ‘MinGW’, ‘MSOCache’, ‘pagefile.sys’, ‘PerfLogs’, ‘Program Files’, ‘ProgramData’, ‘Python27’, ‘Recovery’, ‘System Volume Information’, ‘TURBOC3’, ‘Users’, ‘Windows’]
This is the files inside of my C local disk
if i typed:
listdir(“C:/Python27”) the result will be :
[‘DLLs’, ‘Doc’, ‘error class.py’, ‘f.py’, ‘include’, ‘Lib’, ‘libs’, ‘LICENSE.txt’, ‘NEWS.txt’, ‘python.exe’, ‘pythonw.exe’, ‘README.txt’, ‘Scripts’, ‘tcl’, ‘Tools’, ‘w9xpopen.exe’]
This is the Files and Folders iniside of Python27
Okay let’s talk about rename
rename(‘C:/Users/yossef/Desktop/yossef.txt’,’C:/Users/yossef/Desktop/yossef1.txt’)
the function mkdir makes a file or directory
mkdir(“hey”) #mkdir for make directory
this renames a text file named yossef to yossef1
okay very simple right lets get to another function which is getcwd()
if i typed getcwd() i will get the following result:
‘C:\\Users\\yossef\\AppData\\Local\\Programs\\Python\\Python35-32’
this is the current working directory of python
okay now let’s make a folder or a directory by the function mkdir(make directory)
mkdir(“f”) # this code makes a folder but where ?
here: ‘C:\\Users\\yossef\\AppData\\Local\\Programs\\Python\\Python35-32’
because this the current working directory
what if i want to make it in another place
this is how:
let’s suppose that you want to make a file inside of the f folder well the f folder lies in this directory:
‘C:\\Users\\yossef\\AppData\\Local\\Programs\\Python\\Python35-32’
so i have to change the directory to
‘C:\\Users\\yossef\\AppData\\Local\\Programs\\Python\\Python35-32\\f’
or in code:
chdir(“C:\\Users\\yossef\\AppData\\Local\\Programs\\Python\\Python35-32\\f”)
chdir(change directory changes the current directory)
if i want to make a folder inside of f then i will type mkdir(“the folder name”)
that’s it
rmdir(“the folder name “) # this removes a folder or a directory in the current working directory if you want to remove a file in another place you have to specify the path
i forget something right do you know what is it? it’s if i want to make a file in another place do i have to change it to it’s directory no you have only to specify the path
okay let’s now suppose that i changed the current working directory to C:/users/yossef/Desktop/hey
or in code:
chdir(“C:/users/yossef/Desktop/hey”)
if i typed rmdir(“C:/users/yossef/Desktop/hey”)
a error will pop up:
Traceback (most recent call last):
File “”, line 1, in
os.rmdir(‘C:/users/yossef/Desktop/hey’)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: ‘C:/users/yossef/Desktop/hey’
because the directory is being used by python an error will pop up
well i wan to delete this dir i have to change the directory that python is working on
chdir(“E:/newfile”)
now i can remove the file
rmdir(”C:/users/yossef/Desktop/hey”)
now we will use the system function
system(“shutdown /p”) # WARNING THIS WILL SHUTDOWN YOUR COMPUTER LOL
system is used to send system cmds
the last thing is the walk function
walk(“C://”)
this walks through all the files in the c local disk and give the paths in it
this is the first time i explain something in programming i hope it helps