0% found this document useful (0 votes)
7 views

SearchSubstringInString (C Program)

Uploaded by

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

SearchSubstringInString (C Program)

Uploaded by

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

#include<stdio.

h>
#include<string.h>

int main () {
printf ("Input the string :");
char s[50];
fflush(stdin);
gets(s);
char s1[50];
strcpy(s1,s);

int i,j;
/* de lam duoc bai nay , chung ta phai theo trinh tu :
chuyen cac ki tu thuong sang hoa truoc , roi sau do se tim cac
ki tu dau tien cua moi tu va chuyen no sang in thuong . Neu lam nguoc lai ,
chung ta se nhan dc 1 chuoi ki tu full in hoa ==> sai output.*/

for ( j = 1 ; j < strlen(s) ; j++) {


// dieu kien de tim ra cac chu in thuong trong moi tu
if (s[j] != ' ' && s[j] >= 'a' && s[j] <= 'z') {
s[j]-=32;
}
}
// code chuyen ki tu dau tien cua chuoi tu hoa sang thuong ,
// li do : khi chay vong lap ben duoi , no se chay tu ki tu 2
// tro di , tuc la ki tu thu 1 van se la in hoa neu khong use code ben duoi
nay .
if (s[0] == ' ' && s[1] != ' ' && s[1] >= 'A' && s[1] <= 'Z') {
s[1]+=32;
}

for ( i = 1 ; i < strlen(s) ; i++) {


// dieu kien tim ra ki tu dau cua moi tu
if ( s[i] == ' ' && s[i+1]!=' '&& s[i+1] >= 'A' && s[i+1] <= 'Z') {
s[i+1]+=32;
}
}
printf ("The given sentence is : %s\n",s1 );
printf("After cased changed the string is : %s", s);

printf ("\n");
system("pause");
return 0;
}

You might also like