Lecture 4 Strings
Lecture 4 Strings
-271
Presented By
Saadman Sakib
Lecturer,
Department of CSE,
CUET
Why do we need a terminating null character („\0‟)?
#include <string.h>
#include <stdio.h>
int main()
{
char a[50],b[50];
int i,j,len;
gets(a);
len=strlen(a);
for(i=0,j=len-1;i<len;i++,j--)
b[j]=a[i];
for(i=0;i<len;i++)
putchar(b[i]);
}
#include <stdio.h>
Program-I
int main( )
{
int c,d;
char a[ ] = "CProgramming";
for(c=0;c<=11;c++)
{
d=c+1;
printf("%-12.*s\n",d,a);
}
for(c=11;c>=0;c--)
{
d=c+1;
printf("%-12.*s\n",d,a);
}
return 0;
}
#include <stdio.h>
int main( ) Program-II
{
int c,d;
char a[ ] = "CProgramming";
for(c=0;c<=11;c++)
{
d=c+1;
printf("%12.*s\n",d,a);
}
for(c=11;c>=0;c--)
{
d=c+1;
printf("%12.*s\n",d,a);
}
return 0;
}
C program that reads a string from the keyboard and
determines whether the string is a palindrome or not