Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Tuesday, September 23, 2014

String reversal without string.h

This is a program to reverse a string without the string.h header. If you have any doubts, please do ask.

#include<stdio.h>
main()
{
int i,count=0,j=0;
char string[10],final[10];
scanf("%s",string);
for(i=0;string[i]!='\0';i++)
count++;
count--;
for(i=count;i>=0;i--)
{
final[j]=string[i];
j++;
}
final[j]='\0';
printf("%s",final);
}

Saturday, August 9, 2014

Program to reverse a string

Program to reverse a string. You'll need to work with pointers in this program. If you need help, comment below

#include<stdio.h> #include<string.h> main() { char *ptr; char string[50],t; int i,j,l; ptr=string; printf("\nEnter the string"); gets(string); l=strlen(string); for(i=0,j=l-1;i<=(l-1)/2;i++,j--) { t= *(ptr+i); *(ptr+i)= *(ptr+j); *(ptr+j)=t; } printf("Reverse string is %s\n",string); }

Program to remove the vowels from a string.

Simple C program to remove the vowels from a string. If you have any doubts, please let me know.

#include<stdio.h> #include<string.h> main() { char s[200]; int i=0,j=0,n; printf("\n\n Enter the sentence : "); gets(s); n=strlen(s); while(i<n) { if((s[i]=='a')||(s[i]=='e')||(s[i]=='i')||(s[i]=='o')||(s[i]=='u')||(s[i]=='A')||(s[i]=='E')||(s[i]=='I')||(s[i]=='O')||(s[i]=='U')||(s[i]==' ')) { for(j=i;j<n;j++) { s[j]=s[j+1]; } n--; } else i++; } printf("\n\n New sentence : "); for(i=0;i<n;i++) printf("%c",s[i]); printf("\n\n"); }