Write a C program to reverse a string using pointers.

C Strings:
Write a C program to reverse a string using pointers.
In this program, we reverse the given string by using the pointers. Here we use the two pointers to reverse the string, strptr holds the address of given string and in loop revptr holds the address of the reversed string.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
int main(){
int i=-1;
char str[100];
char rev[100];
char *strptr = str;
char *revptr = rev;
printf("Enter the string:n");
scanf("%s",str);
while(*strptr)
{
strptr++;
i++;
}
while(i >=0) {
strptr--;
*strptr = *revptr;
revptr++;
--i;
}
printf("nn Reversed string is:%s",rev);
return 0;
}



Read more Similar C Programs
 
Searching in C

C Strings 
 
C Aptitude 
 

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to Encrypt and Decrypt a password

C Strings:
Write a C program to Encryption and Decryption of password.
In this program we encrypt the given string by subtracting the hex value from it. Password encryption is required for the security reason, You can use so many functions like hash or other keys to encrypt. Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

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

void encrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] - key;
}
}

void decrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] + key;
}
}
int main()
{
char password[20] ;
printf("Enter the password: n ");
scanf("%s",password);
printf("Passwrod = %sn",password);
encrypt(password,0xFACA);
printf("Encrypted value = %sn",password);
decrypt(password,0xFACA);
printf("Decrypted value = %sn",password);
return 0;
}
Read more Similar C Programs
Learn C Programming
Recursion
Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to check whether two strings are anagrams of each other.

C Strings:
Write a c program to check whether two strings are anagrams of each other.
Two strings are said to be anagrams, if the characters in the strings are same in terms of numbers and value ,only arrangement or order of characters are may be different.
Example: “dfghjkl” and “lkjghdf” are anagrams of each other.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include<stdio.h>
#include<string.h>
# define NO_OF_CHARS 256
int Anagram(char *str1, char *str2)
{
    // Create two count arrays and initialize all values as 0
    int count1[NO_OF_CHARS] = {0};
    int count2[NO_OF_CHARS] = {0};
    int i;
    
    // For each character in input strings, increment count in
    // the corresponding count array
    for (i = 0; str1[i] && str2[i];  i++)
    {
        count1[str1[i]]++;
        count2[str2[i]]++;
    }
    
    // If both strings are of different length. Removing this condition
    // will make the program fail for strings like "aaca" and "aca"
    if (str1[i] || str2[i])
    return 0;
    
    // Compare count arrays
    for (i = 0; i < NO_OF_CHARS; i++)
    if (count1[i] != count2[i])
    return 0;

    return 1;
}
main()
{
    char str[100], str1[100];
    int flag = 0;
    
    printf("Enter first stringn");
    gets(str);
    
    printf("Enter second stringn");
    gets(str1);
    
    flag=Anagram(str, str1);
    if (flag==1)
    printf(""%s" and "%s" are anagrams.n", str, str1);
    else
    printf(""%s" and "%s" are not anagrams.n", str, str1);
    
    return 0;
}

Read more c programs
C Basic
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to delete vowels in a string.

C Strings:
Write a C Program to delete a vowel in a given string.
In this program, We use the pointers to position the characters.check_vowel() function checks the character is vowel or not, if the character is vowel it returns true else false.
Example output:Given string: Check vowel
Output is: Chck vwl
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define TRUE 1
#define FALSE 0

int check_vowel(char);

main()
{
char string[100], *temp, *pointer, ch, *start;
csrcscr();
printf("nnEnter a stringn");
scanf("%s",string);
temp = string;
pointer = (char*)malloc(100);

if( pointer == NULL )
{
printf("Unable to allocate memory.n");
exit(EXIT_FAILURE);
}

start = pointer;

while(*temp)
{
ch = *temp;

if ( !check_vowel(ch) )
{
*pointer = ch;
pointer++;
}
temp++;
}
*pointer = '';

pointer = start;
strcpy(string, pointer); /* If you wish to convert original string */
free(pointer);

printf("String after removing vowels is "%s"n", string);

return 0;
}

int check_vowel(char a)
{
if ( a >= 'A' && a <= 'Z' )
a = a + 'a' - 'A';

if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
return TRUE;

return FALSE;
}
Read more c programs
C Basic
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to demonstrate strspn function.

Write a C Program to demonstrate strspn function.
The strspn() function returns the index of the first character in string1 that doesn’t match any character in string2. If all the characters of the string2 matched with the string1, strspn returns the length of the string1. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
int spn;
char str1[] = "1234hjbcde09i";
char str2[] = "12345";
char str3[] = "a12d3456fd";
char char_list[] = "1234567890";
clrscr();
//It returns 4
spn = strspn (str1,char_list);
printf ("nnThe length of the initial numbers for str1 is %d.n",spn);

//It returns 5
spn = strspn (str2,char_list);
printf ("nThe length of the initial numbers for str2 is %d.n",spn);

//It returns 0
spn = strspn (string3,char_list);
printf ("nThe length of the initial numbers for string3 is %d.n",spn);
return 0;
}

Read more c programs
C Basic
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to replace the sub string with another string.

C Strings:
Write a C program to replace the sub string in a string with another string.
In this program, We replace string with another string, if the entered string is the sub string of main string, otherwise function replace_str returns the original string as it is. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

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

char *replace_str(char *str, char *orig, char *rep)
{
static char buffer[4096];
char *p;

if(!(p = strstr(str, orig)))
return str;

strncpy(buffer, str, p-str);
buffer[p-str] = '';

sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig));

return buffer;
}

int main(void)
{
char str[100],str1[50],str2[50];
printf("Enter a one line string..n");
gets(str);
printf("Enter the sub string to be replaced..n");
gets(str1);
printf("Enter the replacing string....n");
gets(str2);
puts(replace_str(str, str1, str2));

return 0;
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to find all the permutations of a given string.

Write a c program to find all the permutations of a given string.
Example: If the given string is sam, output is,
sam
sma
msa
mas
asm
ams.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

# include<stdio.h>
# include<conio.h>
#include<string.h>
void swap (char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}

void permute(char *a, int i, int n)
{
int j;
if (i == n)
printf("%sn", a);
else
{
for (j = i; j <= n; j++)
{
swap((a+i), (a+j));
permute(a, i+1, n);
swap((a+i), (a+j));
}
}
}


int main()
{
char str[80] ;
int len=0,i;
puts("Enter a string:nn");
gets(str);
for (i=0; str[i] != ''; i++)
{
len++;
}
permute(str, 0, len);
getchar();
return 0;
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to find the position of a sub string.

C Strings:
C Program to find the position of a sub string in a given string.
In this program, We find the position of a sub string where it starts  in the main string. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include <stdio.h>
#include <conio.h>
main()
{
char firststr[30], substr[10];
char *secondstr, *thirdstr;
clrscr();
printf("Enter any string");
scanf("%s",firststr);
printf("Enter sub string");
scanf("%s",substr);
secondstr=firststr;
thirdstr=substr;
i=substr(secondstr, thirdstr);
printf("nn");
if(i!=-1)
printf("The starting location/position of substring in main string: %d", i;
else
printf("String not found");
getch();
}


int substr(secondstr, thirdstr)

{
char *secondstr, *thirdstr;

int j=0,l=0;
static int k;
if(*second==*third)
{
while(i<strlen(third))
{
if(*second==*third)
k=j+1;
else
k+=1;
l++;
}
third++;
second++;
}
second++;
j++;

if(k!=0)
return(k);
else
return(-1);
}
Read more Similar C Programs
Searching in C

C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to copy and concatenate strings without using standard functions.

C Program to copy and concatenate strings without using standard functions.
In this program , we copy one string from another, and without using the standard library function strcpy from string.h .
Here we appends the one string to another without using the strcat function. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>

void newStrCpy(char *,char *);
void newStrCat(char *,char *);

void main()
{
char str1[80],str2[80];
int opn;
do
{
printf("Press 1- NewStrCpy t 2- NewStrCatt 3- Exitt Your Option?");
scanf("%d",&opn);
switch(opn)
{
case 1: flushall();
printf("n Read the Source String n");
gets(str1);
newStrCpy(str2,str1);
printf(" Copied String: %sn",str2);
break;
case 2: flushall();
printf(" Read the First String n");
gets(str1);
printf(" Read the Second String n");
gets(str2);
newStrCat(str1,str2);
printf("Concatenated String: n");
puts(str1);
break;
case 3: printf(" Exit!! Press a key . . .");
getch();
break;
default: printf(" Invalid Option!!! Try again !!!n");
break;
}
}while(opn != 3);
} /* End of main() */

void newStrCpy(char *d,char *s)
{
while( (*d++ = *s++));
}
void newStrCat(char *s, char *t)
{
while(*s)
s++;
while(*s++ = *t++);
}

Read more c programs 
C Basic
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to demonstrate isalpha, isdigit, is space.

C Program to demonstrate the following functions:isalpha, isdigit, isspace.The same principles apply to isalnum, iscntrl, isgraph,islower, isprint, ispunct, isupper, isxdigit.
In the standard library ctype.h all the above functions are declared.
All the subroutines mentioned here, returns non zero(true), If the checked argument is true for the respective subroutines. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h> /* printf */
#include <ctype.h> /* isalpha isdigit isspace etc */

#define FALSE 0
#define TRUE 1

/* function declarations */
int char_type(char);

main()
{
char ch;
/* get a character from the keyboard */
printf(" Please enter a charcater => ");
ch = getc(stdin);

char_type(ch); /* Figure out the character type */


}

//char_type:decides the character type
int char_type(char ch)
{
/* returns non zero if A-Z or a-z */
if ( isalpha(ch) != FALSE)
printf("%c is an Alpha character.n",ch);

/* returns non zero if 0-9 */
if ( isdigit(ch) != FALSE)
printf("%c is a numeric character.n",ch);

/* returns non zero if a space, CR, Tab, NL FF */
if ( isspace(ch) != FALSE)
printf("%c is white spacen", ch);

}

Read more c programs 
C Basic
C Strings

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com