The document discusses strings in C programming. It defines strings as finite sequences of characters that can be implemented as arrays of bytes or characters. It describes common string operations like searching, sorting, trimming, insertion, and deletion. It also lists various string manipulation functions in C like strcat, strcpy, strlen, and their applications in areas like text editing, search engines, and computational biology.
This document provides an overview of string handling functions in C programming. It discusses how to declare strings, compare strings, concatenate strings, copy strings, and manipulate strings using pre-defined functions from the string.h header file. Examples are given for common string functions like strlen(), strcmp(), strcpy(), strcat(), etc. to illustrate how each function works and what it returns.
The document discusses strings in C programming. It defines strings as sequences of characters stored as character arrays that are terminated with a null character. It covers string literals, declaring and initializing string variables, reading and writing strings, and common string manipulation functions like strlen(), strcpy(), strcmp(), and strcat(). These functions allow operations on strings like getting the length, copying strings, comparing strings, and concatenating strings.
02 of 03 parts
Get Part 1 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-1
Get Part 3 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-3
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to PLCs and embedded system.
1) A string is a one-dimensional array of characters terminated by a null character. Strings are declared using char arrays or string literals.
2) There are two ways to declare and initialize strings in C: using a char array and specifying the size, or using a string literal which automatically inserts a null terminator.
3) Common string functions include strlen() to return the length, strcpy() to copy one string to another, strcat() to concatenate strings, and strcmp() to compare two strings.
This document provides information about strings in C++. It defines a string as a collection of characters within double quotes. Strings are stored as character arrays terminated by a null character. The document discusses declaring and initializing strings, inputting strings from the user, and functions for manipulating strings like strcat(), strcmp(), and memcpy(). It also covers arrays of strings and comparing, concatenating, copying and other operations on strings.
This document provides an introduction to strings in C programming, including defining strings as character arrays, initializing strings, inputting and outputting strings, and pointers and strings. It also covers common string library functions like strlen(), strcpy(), strcat(), strcmp(), and strrev(). Finally, it includes examples of basic string programs demonstrating the use of these functions.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described as well as how to initialize, copy, concatenate, compare and get the length of strings. The document provides examples of declaring, initializing and using strings in C code.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described as well as how to initialize, copy, concatenate, compare and find the length of strings. The document provides examples of declaring, initializing and using strings in C code.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described along with examples of how to use each function to copy, concatenate, compare, and find the length of strings. The document provides details on initializing strings, rules for declaring strings, and examples of string operations in C code.
This document discusses strings in C programming. It defines strings as arrays of characters that end with a null terminator (\0). It explains how to initialize and print strings. Common string functions like strlen(), strcpy(), strcat(), and strcmp() are described. The document contrasts strings and character pointers, noting strings cannot be reassigned while pointers can. Finally, it lists and briefly explains other standard string library functions.
This document discusses handling of character strings in C programming. It covers declaring and initializing string variables as character arrays, reading strings from the terminal using scanf() and gets(), writing strings to the screen using printf() and puts(), performing arithmetic operations and comparisons on characters, concatenating strings, and commonly used string handling functions like strcpy(), strcat(), and strcmp().
The document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. It explains that string handling functions are declared in the string.h header file and are used to perform operations on strings like getting the length, concatenating, comparing, and manipulating case. Several functions are described like strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), strupr(). Examples are given showing how to use these functions to work with strings.
This document provides an overview of string handling in C programming. It discusses how strings are represented as character arrays and terminated with a null character. It describes declaring, initializing, and manipulating strings through built-in string functions like strlen(), strcpy(), strcmp(), strcat(), strlwr(), and strrev(). Examples are given to illustrate how each string function works and how to use them to process strings as complete entities.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
This document discusses strings in C programming. It defines strings as arrays of characters terminated with a null character. It describes four methods of initializing strings: assigning a string literal with or without size, assigning characters individually with size, and assigning characters individually without size. It also covers string functions like strlen(), strcpy(), strcat(), and strcmp() to get the length, copy, concatenate, and compare strings. Finally, it discusses string arrays as two-dimensional character arrays where each string is terminated with a null character. An example program is provided to print an array of strings.
A pointer is a variable that stores the address of another variable. Pointers allow a variable to indirectly access and modify the value of another variable. Pointers contain the address of the variable they point to. Common string operations like finding the length, comparing, copying and concatenating strings can be performed using standard library functions like strlen(), strcmp(), strcpy(), and strcat(). These functions make string handling easier compared to writing custom code.
The document discusses strings in C programming language. It provides details about:
- Strings are arrays of characters terminated by a null character '\0'.
- Common functions to declare, initialize, print and manipulate strings like strlen(), strcpy(), strcat(), strcmp() etc.
- Important points about receiving and processing multi-word strings using scanf(), gets() and puts().
- Implementation of some string handling functions like xstrlen(), xstrcpy() to demonstrate their working.
This document discusses handling of character strings in C. It explains that a string is a sequence of characters stored in memory as ASCII codes appended with a null terminator. It describes common string operations in C like reading, displaying, concatenating, comparing and extracting substrings. It also discusses functions like strlen(), strcat(), strcmp(), strcpy() for performing various operations on strings.
Presentation more c_programmingcharacter_and_string_handling_KarthicaMarasamy
The document discusses C string operations like strcpy, strcat, strcmp, and strlen. It provides examples of using each function, including copying one string into another with strcpy, appending strings with strcat, comparing strings alphabetically with strcmp, and getting the length of a string with strlen. It also covers basic string declarations and built-in functions for manipulating characters.
This chapter provides an in-depth overview of the viscosity of macromolecules, an essential concept in biophysics and medical sciences, especially in understanding fluid behavior like blood flow in the human body.
Key concepts covered include:
✅ Definition and Types of Viscosity: Dynamic vs. Kinematic viscosity, cohesion, and adhesion.
⚙️ Methods of Measuring Viscosity:
Rotary Viscometer
Vibrational Viscometer
Falling Object Method
Capillary Viscometer
🌡️ Factors Affecting Viscosity: Temperature, composition, flow rate.
🩺 Clinical Relevance: Impact of blood viscosity in cardiovascular health.
🌊 Fluid Dynamics: Laminar vs. turbulent flow, Reynolds number.
🔬 Extension Techniques:
Chromatography (adsorption, partition, TLC, etc.)
Electrophoresis (protein/DNA separation)
Sedimentation and Centrifugation methods.
Ad
More Related Content
Similar to UNIT 4C-Strings.pptx for c language and basic knowledge (20)
This document provides an introduction to strings in C programming, including defining strings as character arrays, initializing strings, inputting and outputting strings, and pointers and strings. It also covers common string library functions like strlen(), strcpy(), strcat(), strcmp(), and strrev(). Finally, it includes examples of basic string programs demonstrating the use of these functions.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described as well as how to initialize, copy, concatenate, compare and get the length of strings. The document provides examples of declaring, initializing and using strings in C code.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described as well as how to initialize, copy, concatenate, compare and find the length of strings. The document provides examples of declaring, initializing and using strings in C code.
This document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. Strings must be declared as character arrays, specifying the array size. Common string functions like strcpy(), strcat(), strcmp(), and strlen() are described along with examples of how to use each function to copy, concatenate, compare, and find the length of strings. The document provides details on initializing strings, rules for declaring strings, and examples of string operations in C code.
This document discusses strings in C programming. It defines strings as arrays of characters that end with a null terminator (\0). It explains how to initialize and print strings. Common string functions like strlen(), strcpy(), strcat(), and strcmp() are described. The document contrasts strings and character pointers, noting strings cannot be reassigned while pointers can. Finally, it lists and briefly explains other standard string library functions.
This document discusses handling of character strings in C programming. It covers declaring and initializing string variables as character arrays, reading strings from the terminal using scanf() and gets(), writing strings to the screen using printf() and puts(), performing arithmetic operations and comparisons on characters, concatenating strings, and commonly used string handling functions like strcpy(), strcat(), and strcmp().
The document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. It explains that string handling functions are declared in the string.h header file and are used to perform operations on strings like getting the length, concatenating, comparing, and manipulating case. Several functions are described like strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), strupr(). Examples are given showing how to use these functions to work with strings.
This document provides an overview of string handling in C programming. It discusses how strings are represented as character arrays and terminated with a null character. It describes declaring, initializing, and manipulating strings through built-in string functions like strlen(), strcpy(), strcmp(), strcat(), strlwr(), and strrev(). Examples are given to illustrate how each string function works and how to use them to process strings as complete entities.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
Strings in C programming can be represented as arrays of characters terminated by a null character. A string is initialized by enclosing the characters within double quotes. Functions like strcpy(), strcat(), strcmp(), strlen() etc in string.h header file can perform operations on strings like copying, concatenating, comparing and finding length.
This document discusses strings in C programming. It defines strings as arrays of characters terminated with a null character. It describes four methods of initializing strings: assigning a string literal with or without size, assigning characters individually with size, and assigning characters individually without size. It also covers string functions like strlen(), strcpy(), strcat(), and strcmp() to get the length, copy, concatenate, and compare strings. Finally, it discusses string arrays as two-dimensional character arrays where each string is terminated with a null character. An example program is provided to print an array of strings.
A pointer is a variable that stores the address of another variable. Pointers allow a variable to indirectly access and modify the value of another variable. Pointers contain the address of the variable they point to. Common string operations like finding the length, comparing, copying and concatenating strings can be performed using standard library functions like strlen(), strcmp(), strcpy(), and strcat(). These functions make string handling easier compared to writing custom code.
The document discusses strings in C programming language. It provides details about:
- Strings are arrays of characters terminated by a null character '\0'.
- Common functions to declare, initialize, print and manipulate strings like strlen(), strcpy(), strcat(), strcmp() etc.
- Important points about receiving and processing multi-word strings using scanf(), gets() and puts().
- Implementation of some string handling functions like xstrlen(), xstrcpy() to demonstrate their working.
This document discusses handling of character strings in C. It explains that a string is a sequence of characters stored in memory as ASCII codes appended with a null terminator. It describes common string operations in C like reading, displaying, concatenating, comparing and extracting substrings. It also discusses functions like strlen(), strcat(), strcmp(), strcpy() for performing various operations on strings.
Presentation more c_programmingcharacter_and_string_handling_KarthicaMarasamy
The document discusses C string operations like strcpy, strcat, strcmp, and strlen. It provides examples of using each function, including copying one string into another with strcpy, appending strings with strcat, comparing strings alphabetically with strcmp, and getting the length of a string with strlen. It also covers basic string declarations and built-in functions for manipulating characters.
This chapter provides an in-depth overview of the viscosity of macromolecules, an essential concept in biophysics and medical sciences, especially in understanding fluid behavior like blood flow in the human body.
Key concepts covered include:
✅ Definition and Types of Viscosity: Dynamic vs. Kinematic viscosity, cohesion, and adhesion.
⚙️ Methods of Measuring Viscosity:
Rotary Viscometer
Vibrational Viscometer
Falling Object Method
Capillary Viscometer
🌡️ Factors Affecting Viscosity: Temperature, composition, flow rate.
🩺 Clinical Relevance: Impact of blood viscosity in cardiovascular health.
🌊 Fluid Dynamics: Laminar vs. turbulent flow, Reynolds number.
🔬 Extension Techniques:
Chromatography (adsorption, partition, TLC, etc.)
Electrophoresis (protein/DNA separation)
Sedimentation and Centrifugation methods.
The ever evoilving world of science /7th class science curiosity /samyans aca...Sandeep Swamy
The Ever-Evolving World of
Science
Welcome to Grade 7 Science4not just a textbook with facts, but an invitation to
question, experiment, and explore the beautiful world we live in. From tiny cells
inside a leaf to the movement of celestial bodies, from household materials to
underground water flows, this journey will challenge your thinking and expand
your knowledge.
Notice something special about this book? The page numbers follow the playful
flight of a butterfly and a soaring paper plane! Just as these objects take flight,
learning soars when curiosity leads the way. Simple observations, like paper
planes, have inspired scientific explorations throughout history.
How to manage Multiple Warehouses for multiple floors in odoo point of saleCeline George
The need for multiple warehouses and effective inventory management is crucial for companies aiming to optimize their operations, enhance customer satisfaction, and maintain a competitive edge.
Odoo Inventory Rules and Routes v17 - Odoo SlidesCeline George
Odoo's inventory management system is highly flexible and powerful, allowing businesses to efficiently manage their stock operations through the use of Rules and Routes.
Understanding P–N Junction Semiconductors: A Beginner’s GuideGS Virdi
Dive into the fundamentals of P–N junctions, the heart of every diode and semiconductor device. In this concise presentation, Dr. G.S. Virdi (Former Chief Scientist, CSIR-CEERI Pilani) covers:
What Is a P–N Junction? Learn how P-type and N-type materials join to create a diode.
Depletion Region & Biasing: See how forward and reverse bias shape the voltage–current behavior.
V–I Characteristics: Understand the curve that defines diode operation.
Real-World Uses: Discover common applications in rectifiers, signal clipping, and more.
Ideal for electronics students, hobbyists, and engineers seeking a clear, practical introduction to P–N junction semiconductors.
How to Manage Opening & Closing Controls in Odoo 17 POSCeline George
In Odoo 17 Point of Sale, the opening and closing controls are key for cash management. At the start of a shift, cashiers log in and enter the starting cash amount, marking the beginning of financial tracking. Throughout the shift, every transaction is recorded, creating an audit trail.
Exploring Substances:
Acidic, Basic, and
Neutral
Welcome to the fascinating world of acids and bases! Join siblings Ashwin and
Keerthi as they explore the colorful world of substances at their school's
National Science Day fair. Their adventure begins with a mysterious white paper
that reveals hidden messages when sprayed with a special liquid.
In this presentation, we'll discover how different substances can be classified as
acidic, basic, or neutral. We'll explore natural indicators like litmus, red rose
extract, and turmeric that help us identify these substances through color
changes. We'll also learn about neutralization reactions and their applications in
our daily lives.
by sandeep swamy
As of Mid to April Ending, I am building a new Reiki-Yoga Series. No worries, they are free workshops. So far, I have 3 presentations so its a gradual process. If interested visit: https://www.slideshare.net/YogaPrincess
https://ldmchapels.weebly.com
Blessings and Happy Spring. We are hitting Mid Season.
The Pala kings were people-protectors. In fact, Gopal was elected to the throne only to end Matsya Nyaya. Bhagalpur Abhiledh states that Dharmapala imposed only fair taxes on the people. Rampala abolished the unjust taxes imposed by Bhima. The Pala rulers were lovers of learning. Vikramshila University was established by Dharmapala. He opened 50 other learning centers. A famous Buddhist scholar named Haribhadra was to be present in his court. Devpala appointed another Buddhist scholar named Veerdeva as the vice president of Nalanda Vihar. Among other scholars of this period, Sandhyakar Nandi, Chakrapani Dutta and Vajradatta are especially famous. Sandhyakar Nandi wrote the famous poem of this period 'Ramcharit'.
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schoolsdogden2
Algebra 1 is often described as a “gateway” class, a pivotal moment that can shape the rest of a student’s K–12 education. Early access is key: successfully completing Algebra 1 in middle school allows students to complete advanced math and science coursework in high school, which research shows lead to higher wages and lower rates of unemployment in adulthood.
Learn how The Atlanta Public Schools is using their data to create a more equitable enrollment in middle school Algebra classes.
Multi-currency in odoo accounting and Update exchange rates automatically in ...Celine George
Most business transactions use the currencies of several countries for financial operations. For global transactions, multi-currency management is essential for enabling international trade.
UNIT 4C-Strings.pptx for c language and basic knowledge
1. UNIT 4 C
String: Introduction,
predefined string functions,
Manipulation of text data,
Command Line Arguments.
2. • Strings are defined as an array of characters.
• The difference between a character array and a string is the string is
terminated with a special character ‘0’.
Declaration of strings:
• Declaring a string is as simple as declaring a one dimensional array.
• char str_name[size];
•
10. a) strlen
• calculates the length of string
• strlen doesn't count '0' while calculating the length of a string.
11. b) Strcpy
Copies a string into another.
strcpy(s1, s2) copies the second string s2 to the first string s1.
12. C) Strcmp –
strcmp(s1, s2) compares two strings and finds out whether they are same or different.
It compares the two strings character by character till there is a mismatch.
If the two strings are identical, it returns a 0. If not, then it returns the difference between
the ASCII values of the first non-matching pair of characters.
15. e)strlwr()
• The strlwr method is used to convert all the characters in a given string into
lowercase.
16. f) strupr()
• The strupr(string) function returns string characters in uppercase.
17. g) strstr()
The strstr() function returns pointer to the first occurrence of the matched string in the given string.
It is used to return substring from first match till the last character.
Syntax: char *strstr(const char *string, const char *match)
19. /* C program to find the length of a string without using the built-in function */
void main()
{
char string[50];
int i, length = 0;
printf("Enter a string n");
gets(string);
for (i = 0; string[i] != '0'; i++) /* keep going through each character of the string till its end */
{
length++;
}
printf("The length of a string is the number of characters in it n");
printf("So, the length of %s = %dn", string, length);
}
20. Program : Reverse String Without Using Library Function [ Strrev ]
#include<stdio.h>
#include<string.h>
int main() {
char str[100], temp;
int i, j = 0;
printf("nEnter the string :");
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf("nReverse string is :%s", str);
return (0); }
23. Program : Copy One String into Other Without Using Library Function.
#include<stdio.h>
int main() {
char s1[100], s2[100];
int i;
printf("nEnter the string :");
gets(s1);
i = 0;
while (s1[i] != '0’)
{ s2[i] = s1[i];
i++;
}
s2[i] = '0';
printf("nCopied String is %s ", s2);
return (0);
}
24. //lower to upper case without using string function
int main()
{ char str[10];
int i=0;
printf("enter string");
scanf("%s",str);
while(str[i]!='0')
{
str[i]=str[i]-32; // change in case of upper to lower
i++;
}
printf("upper string is %s",str);
getch();
return 0;
}
25. //program to concatenate two strings
#include<stdio.h>
#include<string.h>
void concat(char[], char[]);
int main()
{
char s1[50], s2[30];
printf("nEnter String 1 :");
gets(s1);
printf("nEnter String 2 :");
gets(s2);
concat(s1, s2);
printf("nConcated string is :%s", s1);
return (0);
}
void concat(char s1[], char s2[])
{
int i, j;
i = strlen(s1);
for (j = 0; s2[j] != '0'; i++, j++) {
s1[i] = s2[j];
}
s1[i] = '0';
}
27. //program to find string is palindrome or not using string function
What is Palindrome Number ?
• a word, phrase, or sequence that
reads the same backwards as
forwards
• Some palindrome strings
examples are "dad", "radar",
"madam" etc.
How check given string is
palindrome number or not ?
•
This program works as follows :-
at first we copy the entered string
into a new string, and then we
reverse the new string and then
compares it with original string. If
both of them have same
sequence of characters i.e. they
are identical then the entered
string is a palindrome otherwise
not.
#include <stdio.h>
#include <conio.h>
void main() {
char *a;
int i,len,flag=0;
clrscr();
printf("nENTER A STRING: ");
gets(a);
len=strlen(a);
for (i=0;i<len;i++) {
if(a[i]==a[len-i-1])
flag=flag+1;
}
if(flag==len)
printf("nTHE STRING IS PALINDROM"); else
printf("nTHE STRING IS NOT PALINDROM");
getch();
}
28. //program to find string is palindrome or not without using string function
What is Palindrome Number ?
• a word, phrase, or sequence that
reads the same backwards as
forwards
• Some palindrome strings
examples are "dad", "radar",
"madam" etc.
How check given string is
palindrome number or not ?
•
This program works as follows :-
at first we copy the entered string
into a new string, and then we
reverse the new string and then
compares it with original string. If
both of them have same
sequence of characters i.e. they
are identical then the entered
string is a palindrome otherwise
not.
#include <stdio.h>
#include <string.h>
int main() {
char text[100];
int begin, middle, end, length = 0;
gets(text);
while ( text[length] != '0' )
length++;
end = length - 1;
middle = length/2;
for ( begin = 0 ; begin < middle ; begin++ ) {
if ( text[begin] != text[end] ) {
printf("Not a palindrome.n");
break;
}
end--;
}
if( begin == middle )
printf("Palindrome.n");
return 0;
}
29. Palindrome program for number
#include<stdio.h>
int main()
{
int num,r,sum=0,temp;
printf("Enter a number: ");
scanf("%d",&num);
temp=num;
while(num)
{
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(temp==sum)
printf("%d is a palindrome",temp);
else
printf("%d is not a palindrome",temp);
return 0;
}
30. //To Delete all occurrences of Character from the String
Method Used
1.we have accepted one
string from the user and
character to be deleted
from the user.
2. Now we have passed
these two parameters to
function which will delete
all occurrences of given
character from the string.
3. Whole String will be
displayed as output
except given Character.
#include<string.h>
void del(char str[], char ch);
void main()
{ char str[10];
char ch;
printf("nEnter the string : ");
gets(str);
printf("nEnter character which you want to delete : ");
scanf("%ch", &ch);
del(str, ch);
getch();
}
void del(char str[], char ch)
{ int i, j = 0;
int size;
char ch1;
char str1[10];
size = strlen(str);
for (i = 0; i < size; i++)
{ if (str[i] != ch)
{ ch1 = str[i];
str1[j] = ch1;
j++;
}
}
str1[j] = '0';
printf("ncorrected string is : %s", str1);
}
31. Reverse a string using pointers
#include <stdio.h>
#include <conio.h>
void main()
{
char *s;
int len,i;
clrscr();
printf("nENTER A STRING: ");
gets(s);
len=strlen(s);
printf("nTHE REVERSE OF THE STRING IS:");
for(i=len;i>=0;i--)
printf("%c",*(s+i));
getch();
}
33. • The arguments passed from command line are called command line arguments. These arguments
are handled by main() function.
• To support command line argument, you need to change the structure of main() function as given
below.
int main(int argc, char *argv[] )
Here, argc is an integer value that specifies number of command line arguments passed into the
program, including the name of the program.
The argv[] contains the total number of arguments. The first argument is the file name always.
The array of character pointers, argv contains the list of all the arguments. argv[0] is the name of
the program or an empty string if the name is not available.
Argv[1] to argv[argc-1] specifies the command line argument.
34. #include <stdio.h>
void main(int argc, char *argv[] )
{
printf("Program name is: %sn", argv[0]);
if(argc < 2)
{
printf("No argument passed through command line.n");
}
else
{
printf("First argument is: %sn", argv[1]);
}
}