ProAnswers.org

Write a C program to find length of a given string including and executing spaces using pointers?

 #include<stdio.h>

#include<conio.h>

void main()

{

Char str[20], *s;

int p=0, q=0;

clrscr();

printf(“Enter String:”);

gets(str);

s=str;

while(*s!=‟\0‟)

{

Printf(“%c”, *s);

P++;

S++;

If(*s= =32)

q++;

}

printf(“\n Length of string including spaces: %d”, p);

printf(“\n Length of string excluding spaces: %d”, p-q);

getch();

}

Output:

Enter string: POINTER ARE EASY

POINTERS ARE EASY

Length of string including spaces: 17

Length of string excluding spaces: 15