This question asks you to write three string functions There
Solution
/*a) left padding with blank space*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void padleft(char a[],int n)
{
int i,j,s=strlen(a);// getting the length of the string a
if(s==n ||s==0){
printf(\"%s\",a);
return;
}
else{
char b[50];
strcpy(b,a);//storing a string into b
b[s]=\'\\0\';
for(j=0;j<n;j++)
a[j]=\' \'; //appending n spaces to string a
strcat(a,b); // adding the original string to a
printf(\"%s\",a);
}
}
main(){
char a[]={\"a,b,c,d\"};
padleft(a,5);
};
/* b) Truncating the string with specified number of characters*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void truncate(char a[],int n)
{
int i,s=strlen(a);// getting the length of the string a
if(s==n ||s==0||s<n)
printf(\"%s\",a);
a[s-n]=\'\\0\'; //truncating the string to n characters
printf(\"%s\",a);
}
main(){
char a[]={\"a,b,c,d,e,f\"};
truncate(a,3);
};
/*C.Captalizing the first letter of the word using toupper */
#include <stdio.h>
#include <string.h>
void capitalizeWords(char a[]){
int i;
int l = strlen(a);
a[0]=toUpper(a[0]);
for (i=1;i<l;i++){
if (isalpha(a[i]) && a[i-1] == \' \'){
// picking only first letters of a word.
a[i]= toupper(a[i]);
}
}
}
main(){
char a[] = \"text with lowercase words.\";
capitalizeWords(a);
printf(\" %s\",a);
};

