SlideShare a Scribd company logo
1 of 40
Download to read offline
C Programming - Strings

Organized By: Vinay Arora
               Assistant Professor, CSED
               Thapar University, Patiala
Program - 1

        #include<stdio.h>
        #include<conio.h>
        void main()
         {
          char a[]="CIVIL DEPARTMENT";
          int i=0;
          clrscr();

          for(i=0;i<=15;i++)
           {
            printf("%c",a[i]);
           }
         getch();
         }


                            Vinay Arora
                               CSED
Program – 1 (output)




                Vinay Arora
                   CSED
Program - 2
        #include<stdio.h>
        #include<conio.h>
        void main()
         {
          char a[30]="CIVIL DEPARTMENT";
          int i=0;
          clrscr();

         while(a[i]!='0')
           {
            printf("%c",a[i]);
            i++;
           }
         getch();
         }


                             Vinay Arora
                                CSED
Program – 2 (output)




                Vinay Arora
                   CSED
Program - 3

        #include<stdio.h>
        #include<conio.h>
        void main()
         {
          char a[]="CIVIL DEPARTMENT";
          clrscr();

         printf("%s",a);

         getch();
         }




                           Vinay Arora
                              CSED
Program – 3 (output)




                Vinay Arora
                   CSED
Program - 4
        #include<stdio.h>
        #include<conio.h>

        void main()
         {
          char a1[]={'C','I','V','I','L'};
          char a2[]={'C','I','V','I','L','0'};
          char a3[6]={'C','I','V','I','L'};
          clrscr();

         printf("n%s",a1);
         printf("n%s",a2);
         printf("n%s",a3);

         getch();
         }

                               Vinay Arora
                                  CSED
Program – 4 (output)




                Vinay Arora
                   CSED
Program - 5
       #include<stdio.h>
       #include<conio.h>
       void main()
        {
         char a1[6]={'C','I','V','I','L'};
         clrscr();

        printf("n%s",a1);
        printf("n%.3s",a1);
        printf("n%-6.2s",a1);
        printf("n%6.2s",a1);
        printf("n%10s",a1);
        printf("n%5s",a1);

        getch();
        }

                                Vinay Arora
                                   CSED
Program – 5 (output)




                Vinay Arora
                   CSED
Program - 6
        #include<stdio.h>
        #include<conio.h>
        void main()
         {
          char text[20];
          int length;
          clrscr();

         printf("Type the Text belown");
         gets(text);
         length=strlen(text);
         printf("Length of string = %d",length);

         getch();
         }


                            Vinay Arora
                               CSED
Program – 6 (output)




                Vinay Arora
                   CSED
Program - 7
   #include<stdio.h>
   #include<conio.h>                                      getch();
   void main()
    {                                                       }
     char str1[20], str2[20];
     int length;
     clrscr();

    printf("Enter 1st stringn");
    gets(str1);
    printf("Enter 2nd stringn");
    gets(str2);

    printf("n1st String is --->t%s",str1);
    printf("n2nd String is --->t%s",str2);

    strcpy(str1,str2);

    printf("nn1st String after strcpy() is --->t%s",str1);

                                         Vinay Arora
                                            CSED
Program – 7 (output)




                Vinay Arora
                   CSED
Program - 8
  #include<stdio.h>
  #include<conio.h>                                            getch();
  void main()
   {                                                            }
    char str1[20], str2[20];
    int length;
    clrscr();

   printf("Enter 1st stringn");
   gets(str1);
   printf("Enter 2nd stringn");
   gets(str2);

   printf("n1st String is --->t%s",str1);
   printf("n2nd String is --->t%s",str2);

   strncpy(str1,str2,2);

   printf("nn1st String after strcpy() is --->t%s",str1);
                                          Vinay Arora
                                             CSED
Program – 8 (output)




                Vinay Arora
                   CSED
Program - 9
  #include<stdio.h>
  #include<conio.h>                                         getch();
  void main()
   {                                                        }
    char str1[20], str2[20];
    int result;
    clrscr();

   printf("Enter 1st stringn");
   gets(str1);
   printf("Enter 2nd stringn");
   gets(str2);

   printf("n1st String is --->t%s",str1);
   printf("n2nd String is --->t%s",str2);

   result=strcmp(str1,str2);
   //In case of match result will be ZERO otherwise NON ZERO
   printf("nnResult after Comparing is %d",result);

                                              Vinay Arora
                                                 CSED
Program – 9 (output)




                Vinay Arora
                   CSED
Program – 9 (output)




                Vinay Arora
                   CSED
Program - 10
       #include<stdio.h>
       #include<conio.h>
       void main()
        {
         char str1[20];
         int length;
         clrscr();

        printf("Enter 1st stringn");
        gets(str1);

        printf("n1st String is --->t%s",str1);

        strupr(str1);

        printf("nnString after strupr() is --->t%s",str1);

        getch();
        }
                               Vinay Arora
                                  CSED
Program – 10 (output)




                Vinay Arora
                   CSED
Program - 11
     #include<stdio.h>
     #include<conio.h>                              getch();
     void main()
      {                                              }
       char str1[20],str2[20];
       int length;
       clrscr();

      printf("Enter 1st stringn");
      gets(str1);
      printf("Enter 2nd stringn");
      gets(str2);

      printf("n1st String is --->t%s",str1);
      printf("n2nd String is --->t%s",str2);

      strcat(str1,str2);

      printf("nnString after strcat() is --->t%s",str1);
                                      Vinay Arora
                                         CSED
Program – 11 (output)




                Vinay Arora
                   CSED
Program - 12
   #include<stdio.h>
   #include<conio.h>                                  getch();
   void main()
    {                                                   }
     char str1[20],str2[20];
     int length;
     clrscr();

    printf("Enter 1st stringn");
    gets(str1);
    printf("Enter 2nd stringn");
    gets(str2);

    printf("n1st String is --->t%s",str1);
    printf("n2nd String is --->t%s",str2);

    strcat(str1," ");
    strcat(str1,str2);
    printf("nnString after strcat() is --->t%s",str1);

                                       Vinay Arora
                                          CSED
Program – 12 (output)




                Vinay Arora
                   CSED
Program - 13
       #include<stdio.h>
       #include<conio.h>
       void main()
        {
         char str1[20];
         int length;
         clrscr();

        printf("Enter 1st stringn");
        gets(str1);

        printf("n1st String is --->t%s",str1);

        strrev(str1);

        printf("nnString after strrev() is --->t%s",str1);

        getch();
       }

                                Vinay Arora
                                   CSED
Program – 13 (output)




                Vinay Arora
                   CSED
Program - 14
  #include<stdio.h>                printf("n1st String is --->t%s",str1);
  #include<conio.h>
  void main()                       strrev(str1);
   {
    char c,str1[30];                printf("nnString after strrev() is --->t%s",str1);
    int length,i=0;
    clrscr();                       getch();
                                   }
   printf("Enter 1st stringn");

   c=getchar();
   while(c!='@')
    {
      str1[i]=c;
      i++;
      c=getchar();
    }


                                      Vinay Arora
                                         CSED
Program – 14 (output)




                Vinay Arora
                   CSED
Program – 17
  #include<stdio.h>                  printf("nOriginal String Entered is: %s",str1);
  #include<conio.h>                  printf("nnDuplicate String is: %s",str2);
  #include<string.h>
                                      getch();
  void main()                        }
   {
    char str1[20], str2[20];
    int i;

   clrscr();
   printf("Enter your streamt");
   gets(str1);

   for(i=0;str1[i]!='0';i++)
    str2[i]=str1[i];

   str2[i]='0';
                                    Vinay Arora
                                       CSED
Program – 17 (output)




                Vinay Arora
                   CSED
Program – 18
#include<stdio.h>                          if(text[i]=='o')
#include<conio.h>                              ++o;
#include<string.h>                            }

void main()                                  printf("n'm' found in text = %d times",m);
 {                                           printf("n'r' found in text = %d times",r);
  char text[25]="c programming is good";     printf("n'o' found in text = %d times",o);
  int i,m=0,o=0,r=0;
                                             getch();
 clrscr();                                  }

 for(i=0;i<=25;i++)
  {
   if(text[i]=='m')
    ++m;
   if(text[i]=='r')
   ++r;
                                      Vinay Arora
                                         CSED
Program – 18 (output)




                Vinay Arora
                   CSED
Program – 19
                                           while(i<=j)
   #include<stdio.h>                          {
   #include<conio.h>                           if(str[i]==str[j])
   #include<string.h>                           test=1;
                                               else
   void main()                                  {
    {                                            test=0;
     char str[10];                               break;
                                                }
     int i=0,j,test;
                                             i++;
                                             j--;
    clrscr();                               }
                                              if(test==1)
    printf("Enter the word t");               printf("nword is palindrom");
    gets(str);                                else
                                               printf("nword is not palindrom");
    j=strlen(str)-1;
                                            getch();
                                           }

                                   Vinay Arora
                                      CSED
Program – 19 (output)




                Vinay Arora
                   CSED
Program – 19 (output)




                Vinay Arora
                   CSED
Program – 20
 #include<stdio.h>                       printf("Number of words in line = %d",count);
 #include<conio.h>                        getch();
 #include<string.h>                      }
 void main()
  {
   char text[30];
   int count=0,i=0;

  clrscr();

  printf("Enter the line of textn");
  printf("Give one space after each wordn");
  gets(text);

  while(text[i++]!='0')
  if (text[i]==32 || text[i]=='0')
   count++;

                                          Vinay Arora
                                             CSED
Program – 20 (output)




                Vinay Arora
                   CSED
Thnx…



  Vinay Arora
     CSED

More Related Content

What's hot

ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
C basics
C basicsC basics
C basics
MSc CST
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 

What's hot (20)

C programms
C programmsC programms
C programms
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Double linked list
Double linked listDouble linked list
Double linked list
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Lecture 1 string functions
Lecture 1  string functionsLecture 1  string functions
Lecture 1 string functions
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
programs
programsprograms
programs
 
C basics
C basicsC basics
C basics
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 

Viewers also liked

C Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and ConstantsC Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and Constants
vinay arora
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functions
vinay arora
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continue
vinay arora
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
vinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
vinay arora
 
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & FlowchartC Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
vinay arora
 

Viewers also liked (20)

C Tutorial
C TutorialC Tutorial
C Tutorial
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and ConstantsC Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and Constants
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functions
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continue
 
C programming slide-6
C programming slide-6C programming slide-6
C programming slide-6
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
 
Strings
StringsStrings
Strings
 
Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
 
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & FlowchartC Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
C Prog. - Introduction to Hardware, Software, Algorithm & Flowchart
 
Strings
StringsStrings
Strings
 
C string
C stringC string
C string
 
Strings in C
Strings in CStrings in C
Strings in C
 
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Course Review - Lecture 12 - Next Generation User Interfaces (4018166FNR)
Course Review - Lecture 12 - Next Generation User Interfaces (4018166FNR)Course Review - Lecture 12 - Next Generation User Interfaces (4018166FNR)
Course Review - Lecture 12 - Next Generation User Interfaces (4018166FNR)
 
C programming string
C  programming stringC  programming string
C programming string
 

Similar to C Prog. - Strings (Updated)

Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
SANTOSH RATH
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 

Similar to C Prog. - Strings (Updated) (20)

Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
C Programming
C ProgrammingC Programming
C Programming
 
Arrays
ArraysArrays
Arrays
 
Tharun prakash.pptx
Tharun prakash.pptxTharun prakash.pptx
Tharun prakash.pptx
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Circular queue
Circular queueCircular queue
Circular queue
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Pnno
PnnoPnno
Pnno
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
String
StringString
String
 
Unix Programs
Unix ProgramsUnix Programs
Unix Programs
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 

More from vinay arora (20)

Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable type
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
 
A&D - UML
A&D - UMLA&D - UML
A&D - UML
 
A&D - Object Oriented Design using UML
A&D - Object Oriented Design using UMLA&D - Object Oriented Design using UML
A&D - Object Oriented Design using UML
 
A&D - Input Design
A&D - Input DesignA&D - Input Design
A&D - Input Design
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 

C Prog. - Strings (Updated)

  • 1. C Programming - Strings Organized By: Vinay Arora Assistant Professor, CSED Thapar University, Patiala
  • 2. Program - 1 #include<stdio.h> #include<conio.h> void main() { char a[]="CIVIL DEPARTMENT"; int i=0; clrscr(); for(i=0;i<=15;i++) { printf("%c",a[i]); } getch(); } Vinay Arora CSED
  • 3. Program – 1 (output) Vinay Arora CSED
  • 4. Program - 2 #include<stdio.h> #include<conio.h> void main() { char a[30]="CIVIL DEPARTMENT"; int i=0; clrscr(); while(a[i]!='0') { printf("%c",a[i]); i++; } getch(); } Vinay Arora CSED
  • 5. Program – 2 (output) Vinay Arora CSED
  • 6. Program - 3 #include<stdio.h> #include<conio.h> void main() { char a[]="CIVIL DEPARTMENT"; clrscr(); printf("%s",a); getch(); } Vinay Arora CSED
  • 7. Program – 3 (output) Vinay Arora CSED
  • 8. Program - 4 #include<stdio.h> #include<conio.h> void main() { char a1[]={'C','I','V','I','L'}; char a2[]={'C','I','V','I','L','0'}; char a3[6]={'C','I','V','I','L'}; clrscr(); printf("n%s",a1); printf("n%s",a2); printf("n%s",a3); getch(); } Vinay Arora CSED
  • 9. Program – 4 (output) Vinay Arora CSED
  • 10. Program - 5 #include<stdio.h> #include<conio.h> void main() { char a1[6]={'C','I','V','I','L'}; clrscr(); printf("n%s",a1); printf("n%.3s",a1); printf("n%-6.2s",a1); printf("n%6.2s",a1); printf("n%10s",a1); printf("n%5s",a1); getch(); } Vinay Arora CSED
  • 11. Program – 5 (output) Vinay Arora CSED
  • 12. Program - 6 #include<stdio.h> #include<conio.h> void main() { char text[20]; int length; clrscr(); printf("Type the Text belown"); gets(text); length=strlen(text); printf("Length of string = %d",length); getch(); } Vinay Arora CSED
  • 13. Program – 6 (output) Vinay Arora CSED
  • 14. Program - 7 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20], str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strcpy(str1,str2); printf("nn1st String after strcpy() is --->t%s",str1); Vinay Arora CSED
  • 15. Program – 7 (output) Vinay Arora CSED
  • 16. Program - 8 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20], str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strncpy(str1,str2,2); printf("nn1st String after strcpy() is --->t%s",str1); Vinay Arora CSED
  • 17. Program – 8 (output) Vinay Arora CSED
  • 18. Program - 9 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20], str2[20]; int result; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); result=strcmp(str1,str2); //In case of match result will be ZERO otherwise NON ZERO printf("nnResult after Comparing is %d",result); Vinay Arora CSED
  • 19. Program – 9 (output) Vinay Arora CSED
  • 20. Program – 9 (output) Vinay Arora CSED
  • 21. Program - 10 #include<stdio.h> #include<conio.h> void main() { char str1[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("n1st String is --->t%s",str1); strupr(str1); printf("nnString after strupr() is --->t%s",str1); getch(); } Vinay Arora CSED
  • 22. Program – 10 (output) Vinay Arora CSED
  • 23. Program - 11 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20],str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strcat(str1,str2); printf("nnString after strcat() is --->t%s",str1); Vinay Arora CSED
  • 24. Program – 11 (output) Vinay Arora CSED
  • 25. Program - 12 #include<stdio.h> #include<conio.h> getch(); void main() { } char str1[20],str2[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("Enter 2nd stringn"); gets(str2); printf("n1st String is --->t%s",str1); printf("n2nd String is --->t%s",str2); strcat(str1," "); strcat(str1,str2); printf("nnString after strcat() is --->t%s",str1); Vinay Arora CSED
  • 26. Program – 12 (output) Vinay Arora CSED
  • 27. Program - 13 #include<stdio.h> #include<conio.h> void main() { char str1[20]; int length; clrscr(); printf("Enter 1st stringn"); gets(str1); printf("n1st String is --->t%s",str1); strrev(str1); printf("nnString after strrev() is --->t%s",str1); getch(); } Vinay Arora CSED
  • 28. Program – 13 (output) Vinay Arora CSED
  • 29. Program - 14 #include<stdio.h> printf("n1st String is --->t%s",str1); #include<conio.h> void main() strrev(str1); { char c,str1[30]; printf("nnString after strrev() is --->t%s",str1); int length,i=0; clrscr(); getch(); } printf("Enter 1st stringn"); c=getchar(); while(c!='@') { str1[i]=c; i++; c=getchar(); } Vinay Arora CSED
  • 30. Program – 14 (output) Vinay Arora CSED
  • 31. Program – 17 #include<stdio.h> printf("nOriginal String Entered is: %s",str1); #include<conio.h> printf("nnDuplicate String is: %s",str2); #include<string.h> getch(); void main() } { char str1[20], str2[20]; int i; clrscr(); printf("Enter your streamt"); gets(str1); for(i=0;str1[i]!='0';i++) str2[i]=str1[i]; str2[i]='0'; Vinay Arora CSED
  • 32. Program – 17 (output) Vinay Arora CSED
  • 33. Program – 18 #include<stdio.h> if(text[i]=='o') #include<conio.h> ++o; #include<string.h> } void main() printf("n'm' found in text = %d times",m); { printf("n'r' found in text = %d times",r); char text[25]="c programming is good"; printf("n'o' found in text = %d times",o); int i,m=0,o=0,r=0; getch(); clrscr(); } for(i=0;i<=25;i++) { if(text[i]=='m') ++m; if(text[i]=='r') ++r; Vinay Arora CSED
  • 34. Program – 18 (output) Vinay Arora CSED
  • 35. Program – 19 while(i<=j) #include<stdio.h> { #include<conio.h> if(str[i]==str[j]) #include<string.h> test=1; else void main() { { test=0; char str[10]; break; } int i=0,j,test; i++; j--; clrscr(); } if(test==1) printf("Enter the word t"); printf("nword is palindrom"); gets(str); else printf("nword is not palindrom"); j=strlen(str)-1; getch(); } Vinay Arora CSED
  • 36. Program – 19 (output) Vinay Arora CSED
  • 37. Program – 19 (output) Vinay Arora CSED
  • 38. Program – 20 #include<stdio.h> printf("Number of words in line = %d",count); #include<conio.h> getch(); #include<string.h> } void main() { char text[30]; int count=0,i=0; clrscr(); printf("Enter the line of textn"); printf("Give one space after each wordn"); gets(text); while(text[i++]!='0') if (text[i]==32 || text[i]=='0') count++; Vinay Arora CSED
  • 39. Program – 20 (output) Vinay Arora CSED
  • 40. Thnx… Vinay Arora CSED