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

Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep 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 Rahul Chugh
 
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 filesNitesh Dubey
 
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.2020vrgokila
 
Lecture 1 string functions
Lecture 1  string functionsLecture 1  string functions
Lecture 1 string functionsAwinash Goswami
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซีkramsri
 
C basics
C basicsC basics
C basicsMSc 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 Tutorial
C TutorialC Tutorial
C Tutorialbiochelo
 
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 Constantsvinay arora
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functionsvinay arora
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continuevinay arora
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controlsvinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphicsvinay arora
 
Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawlervinay 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 & Flowchartvinay arora
 
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)Beat Signer
 
C programming - String
C programming - StringC programming - String
C programming - StringAchyut Devkota
 
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)Beat Signer
 
C programming string
C  programming stringC  programming string
C programming stringargusacademy
 

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)

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

Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)vinay arora
 
Use case diagram
Use case diagramUse case diagram
Use case diagramvinay arora
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)vinay arora
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)vinay arora
 
4 java - decision
4  java - decision4  java - decision
4 java - decisionvinay arora
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable typevinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operatorsvinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data typevinay arora
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protectionvinay arora
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronizationvinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitivesvinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devicesvinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devicesvinay arora
 
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 UMLvinay arora
 
A&D - Input Design
A&D - Input DesignA&D - Input Design
A&D - Input Designvinay arora
 

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

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
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.pdfAdmir Softic
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 

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