Trim leading white space characters from given string
C program to trim leading white space characters from given string.
Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 50
void main()
{
char str[MAX];
int i, pos;
printf("Enter the string\t:");
gets(str);
printf("\nOriginal String\t:%s",str);
pos = 0;
while(str[pos]==' ' || str[pos]=='\t')
{
pos++;
}
if(pos != 0)
{
i = 0;
while(str[i+pos]!='\0')
{
str[i] = str[i+pos];
i++;
}
str[i] = '\0';
}
printf("\nModified string\t:%s",str);
getch();
}
Output
Enter the string : welcome to coursecrux.com
Original String : welcome to coursecrux.com
Modified string :welcome to coursecrux.com