C-Week1
C-Week1
C Programing
Tr.Pwint Phyu Shwe
Envioronment
• http://www.Cygwin.com
• http://cygwin.com/cygwin-ug-net/cygwin-ug-net.html
• PATH %PATH%;c:\cygwin\bin
Standard
• Preprocessor
• Library/header
#include <stdio.h>
• Entry
int main(){return 0;}
main(){}
Escape Sequence
Escape Sequence Purpose Example
\n Create new line
\t Create tab
\r Move cursor to the beginning of current
line
\\ Insert backslash C:\
\” Double quote ”This is sample”
\’ Single quote Susan’s house
Example:
printf("\nSun\tMon\tTue\tWed\tThu\tFri\tSat\n");
printf("\t\t\t\t1\t2\t3\n");
printf("4\t5\t6\t7\t8\t9\t10\n");
Compilation
compiler
• gcc <filename.c> => default a.out
• gcc <programName.c> –o <executableName.out> => executableName
• gcc <programName.c> –o <executableName> => executableName
Run Program
• ./a.out
• executableName
Primary Data Type
Data Types
Integers – int , short , long
Floating Point – float, double
Character – char
0x001
Declaration
<data types> < variable name> = <value>
int x;
Assignment
int x = 10;
Print content
int x;
float y; Placeholder
char c;
%d
%f
x = -44;
%c
y = 10.33;
c = ‘z’; %.2f
int %d
char %c
float %f
double %lf
unsigned int %u
signed char %c
unsigned char %c
Symbol Operation
+ x+y 13
- x-y 7
* x*y 30
/ x/y 3.333
% x%y 1
Precedence
1. */ %
2. +-
Char Array
• Characters array Dynamic array using Pointer
char myString[5] = {‘J', ‘a', ‘m', ’e’, ’s’, '\0'};
char myString[] = “James”;
Pointer Character (To explain details in next chapert)
char *myString = ”James";
case 10:
X*=10;
break;
default: printf(“there is no value relevant”);
}
Begin
yes
encrypt Do encrypt
No
yes
decrypt Do decrypt
No
yes
encode Do encode
No
yes
decode Do encode
No
Error