• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

String Operations in C Language

July 6, 2013 by ProjectsGeek Leave a Comment

Simple String Operations in C Language

Write a Simple String Operations program in C to perform String operations on strings using library functions

  • Concatenate a string S3 to string S2.
  • Copy a string S3 to another string S2.
  • Find the length of a given string
  • Compare two strings S2 and S3.

Simple String Operations Code

#include <stdio.h>
#include <string.h>
#include<conio.h>
#define MAXLEN 120
void main()
{
char string1[MAXLEN], string2[MAXLEN]; 
char result[MAXLEN]; 
int choice,activity;
int comparison;
clrscr();
while(1)
{

printf(“Enter your choice :\n”);

printf(“1. Enter the strings\n”);
printf(“2. To concatenate a string S2 to string S1\n”);
printf(“3. To find the length of a given string\n”);
printf(“4. To compare two strings S1 and S2.\n”);
printf(“5. To copy a string S2 to another string S1.\n”);
printf(“6. Display S1 and S2.\n”);
printf(“0. Exit \n\n”);
printf(“Your Choice: “);

scanf(“%d”, &choice);

switch(choice)
{

case 1:

printf(“Please enter first string (maximum length %d) \n”, MAXLEN – 1);
flushall();
gets(string1);

printf(“Please enter second string (maximum length %d) \n”, MAXLEN – 1);
flushall();
gets(string2);
break;
case 2:
strcat(string1, string2);

printf(“S1 now is :\n%s\n”, string1);

break;
case 3:
printf(“Please select a string to find length of\n”);

printf(“1. S1\n”);
printf(“2. S2\n”);
printf(“3. New string\n”);

scanf(“%d”, &activity);

switch(activity)
{
case 1:
printf(“The length is %d\n”, strlen(string1));

break;
case 2:
printf(“The length is %d\n”, strlen(string2));

break;
case 3:
printf(“Please enter new string (maximum length %d) \n”, MAXLEN – 1);
scanf(“%s”,result);
printf(“The length is %d\n”, strlen(result));

break;
}
break;
case 4:
comparison = strcmp(string1,string2);

if(comparison < 0)
{
printf(“S1 is lexicographically equal to S2\n”);

}
else if (comparison < 0)
{
printf(“S1 is lexicographically smaller than S2\n”);

}
else
{
printf(“S1 is lexicographically greater than S2\n”);

}
break;
case 5:
strcpy(string1, string2);

printf(“S1 is now :\n%s\n”, string1);

break;
case 6:
printf(“S1 is now :\n%s\n”, string1);
printf(“S2 is now :\n%s\n”, string2);
break;
case 0: exit();

}
printf(“\n\n”);
}
}

 

Other Projects to Try:

  1. Bitwise Operations using C++
  2. String Operations with Pointers
  3. String Operations in C Program
  4. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  5. Matrix Operations in C Language

Filed Under: Uncategorized

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy