SlideShare a Scribd company logo
Array Programming in C
Studying C Coding from Embedded System Perspective
Array
C Programming course for beginners and intermideate
C Programming course for beginners and intermideate
Character Array
in C
Strings and Char operations for
embedded systems
Char
Every printable
character is
represented by
its ASCII Code
01
ASCII code is
max 7 bit long
02
unsigned or
signed char
can be used
03
An array of
char variables
is also called
string
04
Printing a char
%c can be used with printf to print a single char
putchar can be used to print a single char
%s can be used with printf to print a string
Puts can be used to print a string
How char is scanned
• When we scan a char using %c directive, then the
decimal equivalent of the character that you
entered is saved in the variable
• When you print it using %c directive, then the
decimal number is “AS IS” sent to print buffer, and
since it resemebles an actual ascii code of a letter,
the letter is printed.
Scan ( input
a char)
Single char can be input with scanf function using %c
single char can be input with getchar function
String can be input with scanf function using %s
String can be input with gets function
None of scnaf / printf / getchar / gets / puts / putchar
functions are available in Embedded Systems
Character Comparison
char my = ‘a’
if(my == ‘a’)
{
}
String Comparison
char a[10] = “welcome”
if(strcmp(a, “welcome”) == 0)
{
}
String Functions
in C ( also
available in all
embedded
systems)
Sr.No. Function & Purpose
1 strcpy(s1, s2);
Copies string s2 into string s1.
2 strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Returns the length of string s1.
4 strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than
0 if s1>s2.
5 strchr(s1, ch);
Returns a pointer to the first occurrence of character ch in string s1.
6 strstr(s1, s2);
Returns a pointer to the first occurrence of string s2 in string s1.
sprintf
Convert float/int to string in Embedded C
C Programming course for beginners and intermideate
Pointers in C
Very important for Embedded Systems
Pointer Syntax in Declaration
int *a;
int *p;
Assigning addresses to Pointers
“Address of”(&) Operator
int *p
int c;
c = 5;
p = &c;
Get Value of Thing Pointed by Pointers
“Value at Address”(*) Operator
int *p;
int c;
c = 5;
p = &c;
printf("%d", *p); // Output: 5
Functions in C
Functions
Codes that need to
repeat
Function without any
argument
Function with one or
more argument
Function that returns one
argument
Function Syntax
Function_datatype function_name(arguments)
{
return arguments_if_any
}
Functions to return
multiple values
• Using pointers to return multiple
values
• Pass on the address of variables
function_name(&a, &b)
• Write on these values
Global and Local
Variables
C Functions demystified
Array Argument
in Function
How to Pass an array to function in C
Function to
Accept char array
and String
Switch Case
in C
switch
switch (expression)
​
{
case constant1:
// statements
break;
case constant2:
// statements
break;
.
.
.
default:
// default statements
}
How switch
case is
executed
• The expression is evaluated once and
compared with the values of each case label.
• If there is a match, the corresponding
statements after the matching label are
executed.
• For example, if the value of the expression is
equal to constant2, statements after case
constant2: are executed until break is
encountered.
• If there is no match, the default statements
are executed.
Preprocessor
Directives
In C Coding
What are pre-processor directives?
• Basically a text substitution tool
• Begins with # symbol (remember #include )
Example
• stdio.h is a header file. The #include preprocessor directive replaces
the above line with the contents of stdio.h header file.
• You can also create your own header file containing function
declaration and include it in your program using this
preprocessor directive.
• #include “my_header.h”
• This file should be present in the same folder where your main c code
is placed
#define Substitutes a preprocessor macro.
#include Inserts a particular header from another file.
#ifdef Returns true if this macro is defined.
#ifndef Returns true if this macro is not defined.
#if Tests if a compile time condition is true.
#else The alternative for #if.
#elif #else and #if in one statement.
#endif Ends preprocessor conditional.
#error Prints error message on stderr.
#pragma Issues special commands to the compiler, using
a standardized method.
• #define MAX_ARRAY_LENGTH 20
• This directive tells the preprocessor to replace instances of
MAX_ARRAY_LENGTH with 20.
• We Use #define for constants to increase readability.
Define Macro using #define
• #define message_for(a, b) printf(#a " and " #b ": We love you!n")
Ad

More Related Content

Similar to C Programming course for beginners and intermideate (20)

Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
C programming
C programmingC programming
C programming
PralhadKhanal1
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
Hemantha Kulathilake
 
Ch09
Ch09Ch09
Ch09
Arriz San Juan
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
The New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of theThe New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 
programming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptxprogramming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptx
BamaSivasubramanianP
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
Rubal Bansal
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
Koganti Ravikumar
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
Icaii Infotech
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdfqb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
Yashsharma304389
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
Mehul Desai
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
Hemantha Kulathilake
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
The New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of theThe New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 
programming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptxprogramming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptx
BamaSivasubramanianP
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
Icaii Infotech
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 

More from MahmoudElsamanty (7)

Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001
MahmoudElsamanty
 
Lecture 03 Programming C for Beginners 001
Lecture 03 Programming C for Beginners 001Lecture 03 Programming C for Beginners 001
Lecture 03 Programming C for Beginners 001
MahmoudElsamanty
 
Lecture 02 Programming C for Beginners 001
Lecture 02 Programming C for Beginners 001Lecture 02 Programming C for Beginners 001
Lecture 02 Programming C for Beginners 001
MahmoudElsamanty
 
Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
lecture03_EmbeddedSoftware for Beginners
lecture03_EmbeddedSoftware for Beginnerslecture03_EmbeddedSoftware for Beginners
lecture03_EmbeddedSoftware for Beginners
MahmoudElsamanty
 
ECE-3567-Lecture-2-Spring-2025 for beginners
ECE-3567-Lecture-2-Spring-2025 for beginnersECE-3567-Lecture-2-Spring-2025 for beginners
ECE-3567-Lecture-2-Spring-2025 for beginners
MahmoudElsamanty
 
ECE-3567-Lecture-1-Spring-2025 for beginner
ECE-3567-Lecture-1-Spring-2025 for beginnerECE-3567-Lecture-1-Spring-2025 for beginner
ECE-3567-Lecture-1-Spring-2025 for beginner
MahmoudElsamanty
 
Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001Lecture 04 Programming C for Beginners 001
Lecture 04 Programming C for Beginners 001
MahmoudElsamanty
 
Lecture 03 Programming C for Beginners 001
Lecture 03 Programming C for Beginners 001Lecture 03 Programming C for Beginners 001
Lecture 03 Programming C for Beginners 001
MahmoudElsamanty
 
Lecture 02 Programming C for Beginners 001
Lecture 02 Programming C for Beginners 001Lecture 02 Programming C for Beginners 001
Lecture 02 Programming C for Beginners 001
MahmoudElsamanty
 
Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
lecture03_EmbeddedSoftware for Beginners
lecture03_EmbeddedSoftware for Beginnerslecture03_EmbeddedSoftware for Beginners
lecture03_EmbeddedSoftware for Beginners
MahmoudElsamanty
 
ECE-3567-Lecture-2-Spring-2025 for beginners
ECE-3567-Lecture-2-Spring-2025 for beginnersECE-3567-Lecture-2-Spring-2025 for beginners
ECE-3567-Lecture-2-Spring-2025 for beginners
MahmoudElsamanty
 
ECE-3567-Lecture-1-Spring-2025 for beginner
ECE-3567-Lecture-1-Spring-2025 for beginnerECE-3567-Lecture-1-Spring-2025 for beginner
ECE-3567-Lecture-1-Spring-2025 for beginner
MahmoudElsamanty
 
Ad

Recently uploaded (20)

highend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptxhighend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptx
elhadjcheikhdiop
 
data science data stoger Presentation1.pptx
data science data stoger Presentation1.pptxdata science data stoger Presentation1.pptx
data science data stoger Presentation1.pptx
sandeepsherkhane830
 
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHostingTop Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
steve198109
 
Understanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep WebUnderstanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep Web
nabilajabin35
 
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 SupportReliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
steve198109
 
Computers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers NetworksComputers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers Networks
Tito208863
 
5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx
andani26
 
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
DataProvider1
 
final project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptxfinal project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptx
ESTEFANOANDREYGARCIA
 
White and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptxWhite and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptx
canumatown
 
IT Services Workflow From Request to Resolution
IT Services Workflow From Request to ResolutionIT Services Workflow From Request to Resolution
IT Services Workflow From Request to Resolution
mzmziiskd
 
(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security
aluacharya169
 
Best web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you businessBest web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you business
steve198109
 
Determining Glass is mechanical textile
Determining  Glass is mechanical textileDetermining  Glass is mechanical textile
Determining Glass is mechanical textile
Azizul Hakim
 
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation TemplateSmart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
yojeari421237
 
Perguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolhaPerguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolha
socaslev
 
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
David Bernard Ezell
 
How to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any DowntimeHow to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any Downtime
steve198109
 
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC
 
What's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff HustonWhat's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff Huston
APNIC
 
highend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptxhighend-srxseries-services-gateways-customer-presentation.pptx
highend-srxseries-services-gateways-customer-presentation.pptx
elhadjcheikhdiop
 
data science data stoger Presentation1.pptx
data science data stoger Presentation1.pptxdata science data stoger Presentation1.pptx
data science data stoger Presentation1.pptx
sandeepsherkhane830
 
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHostingTop Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
Top Vancouver Green Business Ideas for 2025 Powered by 4GoodHosting
steve198109
 
Understanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep WebUnderstanding the Tor Network and Exploring the Deep Web
Understanding the Tor Network and Exploring the Deep Web
nabilajabin35
 
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 SupportReliable Vancouver Web Hosting with Local Servers & 24/7 Support
Reliable Vancouver Web Hosting with Local Servers & 24/7 Support
steve198109
 
Computers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers NetworksComputers Networks Computers Networks Computers Networks
Computers Networks Computers Networks Computers Networks
Tito208863
 
5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx5-Proses-proses Akuisisi Citra Digital.pptx
5-Proses-proses Akuisisi Citra Digital.pptx
andani26
 
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...Mobile database for your company telemarketing or sms marketing campaigns. Fr...
Mobile database for your company telemarketing or sms marketing campaigns. Fr...
DataProvider1
 
final project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptxfinal project for icpna b08 if someone want.pptx
final project for icpna b08 if someone want.pptx
ESTEFANOANDREYGARCIA
 
White and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptxWhite and Red Clean Car Business Pitch Presentation.pptx
White and Red Clean Car Business Pitch Presentation.pptx
canumatown
 
IT Services Workflow From Request to Resolution
IT Services Workflow From Request to ResolutionIT Services Workflow From Request to Resolution
IT Services Workflow From Request to Resolution
mzmziiskd
 
(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security(Hosting PHising Sites) for Cryptography and network security
(Hosting PHising Sites) for Cryptography and network security
aluacharya169
 
Best web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you businessBest web hosting Vancouver 2025 for you business
Best web hosting Vancouver 2025 for you business
steve198109
 
Determining Glass is mechanical textile
Determining  Glass is mechanical textileDetermining  Glass is mechanical textile
Determining Glass is mechanical textile
Azizul Hakim
 
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation TemplateSmart Mobile App Pitch Deck丨AI Travel App Presentation Template
Smart Mobile App Pitch Deck丨AI Travel App Presentation Template
yojeari421237
 
Perguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolhaPerguntas dos animais - Slides ilustrados de múltipla escolha
Perguntas dos animais - Slides ilustrados de múltipla escolha
socaslev
 
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...Virtualization Trends  Streamlining Operations in Telecom with David Bernard ...
Virtualization Trends Streamlining Operations in Telecom with David Bernard ...
David Bernard Ezell
 
How to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any DowntimeHow to Switch Hosting Providers in Vancouver Without Any Downtime
How to Switch Hosting Providers in Vancouver Without Any Downtime
steve198109
 
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC -Policy Development Process, presented at Local APIGA Taiwan 2025
APNIC
 
What's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff HustonWhat's going on with IPv6? presented by Geoff Huston
What's going on with IPv6? presented by Geoff Huston
APNIC
 
Ad

C Programming course for beginners and intermideate

  • 1. Array Programming in C Studying C Coding from Embedded System Perspective
  • 5. Character Array in C Strings and Char operations for embedded systems
  • 6. Char Every printable character is represented by its ASCII Code 01 ASCII code is max 7 bit long 02 unsigned or signed char can be used 03 An array of char variables is also called string 04
  • 7. Printing a char %c can be used with printf to print a single char putchar can be used to print a single char %s can be used with printf to print a string Puts can be used to print a string
  • 8. How char is scanned • When we scan a char using %c directive, then the decimal equivalent of the character that you entered is saved in the variable • When you print it using %c directive, then the decimal number is “AS IS” sent to print buffer, and since it resemebles an actual ascii code of a letter, the letter is printed.
  • 9. Scan ( input a char) Single char can be input with scanf function using %c single char can be input with getchar function String can be input with scanf function using %s String can be input with gets function None of scnaf / printf / getchar / gets / puts / putchar functions are available in Embedded Systems
  • 10. Character Comparison char my = ‘a’ if(my == ‘a’) { }
  • 11. String Comparison char a[10] = “welcome” if(strcmp(a, “welcome”) == 0) { }
  • 12. String Functions in C ( also available in all embedded systems) Sr.No. Function & Purpose 1 strcpy(s1, s2); Copies string s2 into string s1. 2 strcat(s1, s2); Concatenates string s2 onto the end of string s1. 3 strlen(s1); Returns the length of string s1. 4 strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2. 5 strchr(s1, ch); Returns a pointer to the first occurrence of character ch in string s1. 6 strstr(s1, s2); Returns a pointer to the first occurrence of string s2 in string s1.
  • 13. sprintf Convert float/int to string in Embedded C
  • 15. Pointers in C Very important for Embedded Systems
  • 16. Pointer Syntax in Declaration int *a; int *p;
  • 17. Assigning addresses to Pointers “Address of”(&) Operator int *p int c; c = 5; p = &c;
  • 18. Get Value of Thing Pointed by Pointers “Value at Address”(*) Operator int *p; int c; c = 5; p = &c; printf("%d", *p); // Output: 5
  • 20. Functions Codes that need to repeat Function without any argument Function with one or more argument Function that returns one argument
  • 22. Functions to return multiple values • Using pointers to return multiple values • Pass on the address of variables function_name(&a, &b) • Write on these values
  • 23. Global and Local Variables C Functions demystified
  • 24. Array Argument in Function How to Pass an array to function in C
  • 25. Function to Accept char array and String
  • 27. switch switch (expression) ​ { case constant1: // statements break; case constant2: // statements break; . . . default: // default statements }
  • 28. How switch case is executed • The expression is evaluated once and compared with the values of each case label. • If there is a match, the corresponding statements after the matching label are executed. • For example, if the value of the expression is equal to constant2, statements after case constant2: are executed until break is encountered. • If there is no match, the default statements are executed.
  • 30. What are pre-processor directives? • Basically a text substitution tool • Begins with # symbol (remember #include )
  • 31. Example • stdio.h is a header file. The #include preprocessor directive replaces the above line with the contents of stdio.h header file. • You can also create your own header file containing function declaration and include it in your program using this preprocessor directive. • #include “my_header.h” • This file should be present in the same folder where your main c code is placed
  • 32. #define Substitutes a preprocessor macro. #include Inserts a particular header from another file. #ifdef Returns true if this macro is defined. #ifndef Returns true if this macro is not defined. #if Tests if a compile time condition is true. #else The alternative for #if. #elif #else and #if in one statement. #endif Ends preprocessor conditional. #error Prints error message on stderr. #pragma Issues special commands to the compiler, using a standardized method.
  • 33. • #define MAX_ARRAY_LENGTH 20 • This directive tells the preprocessor to replace instances of MAX_ARRAY_LENGTH with 20. • We Use #define for constants to increase readability.
  • 34. Define Macro using #define • #define message_for(a, b) printf(#a " and " #b ": We love you!n")