0% found this document useful (0 votes)
16 views8 pages

C Programs for Character and String Handling

The document contains several C programs demonstrating character and string handling functions, including reading characters, checking if a character is an alphabet, converting case, and manipulating strings using functions like strlen, strcpy, and strcmp. Each program is structured to prompt for user input and display results based on the operations performed. The examples illustrate basic input/output operations and string manipulation techniques in C programming.

Uploaded by

aryabardhan791
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

C Programs for Character and String Handling

The document contains several C programs demonstrating character and string handling functions, including reading characters, checking if a character is an alphabet, converting case, and manipulating strings using functions like strlen, strcpy, and strcmp. Each program is structured to prompt for user input and display results based on the operations performed. The examples illustrate basic input/output operations and string manipulation techniques in C programming.

Uploaded by

aryabardhan791
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

:: CHARACTER HANDLING ::

/* prog30.c */

# include <stdio.h>
#include <conio.h>

int main()
{

char ch;
clrscr();

printf("Enter a character:\n");

ch = getchar();

printf("The character is :");

putchar(ch);

return 0;

}
/* prog31.c */

/* C example program of isalpha().*/


#include<stdio.h>
#include<ctype.h>
#include <conio.h>

int main()
{
char ch;
clrscr();
printf("Enter a character: ");
scanf("%c",&ch);

if(isalpha(ch))
printf("%c is an alphabet.\n",ch);
else
printf("%c is not an alphabet.\n",ch);

return 0;
}
/* prog34.c */

/* C example program of toupper() and tolower() .*/


#include<stdio.h>
#include<ctype.h>
#include <conio.h>

int main()
{
char ch;
clrscr();
printf("Enter a character: ");
scanf("%c",&ch);

if(islower(ch))

printf("Upper case: %c", toupper(ch));


else
printf("Lower case: %c\n",tolower(ch));

return 0;
}
:: STRING ::

/* prog35.c */

/* Using scanf() and printf() with String */

# include <stdio.h>
#include <conio.h>

void main()
{
char arr[50];
clrscr();
printf("Enter a String:\n");

scanf("%s",arr);

printf("The String is:%s",arr);

}
/* input and output multi word string */
/* prog36.c */

# include <stdio.h>
#include <conio.h>

void main()
{
char arr[40];
clrscr();
printf("Enter string:\n");

gets(arr);

printf("String:");

puts(arr);

}
/* prog37.c */

/* Program using strlen() function */


#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
char a[20]="George Telegraph";
char b[50]=”136, B B Ganguly Street”;

clrscr();

printf("Length of string a = %u \n",strlen(a));

printf("Length of string b = %u \n",strlen(b));

}
/* prog38.c */

/* Program using strcpy() function */


#include <stdio.h>
#include <string.h>
#include <conio.h>

void main()
{
char str1[20] = "Programming in C";

char str2[20];
clrscr();

strcpy(str2, str1);

printf("Output String:\n");

puts(str2);

}
/* prog39.c */

/* program using strcmp() function with string */


#include <stdio.h>
#include <string.h>
#include <conio.h>

void main()
{
char str1[] = "abcd", str2[] = "abcd", str3[] = "quty";
int result;
clrscr();

result = strcmp(str1, str2);

if(result == 0)
printf("str1 and str2 are Equal\n");
else
printf("str1 and str2 are not Equal\n");

result = strcmp(str1, str3);

if(result == 0)
printf("str1 and str3 are Equal\n");
else
printf("str1 and str3 are not Equal\n");

You might also like