-->

WAP to count all characters after first white space

in turboc++
----------------------------------------------------------------------------------------
//WAP to count all characters after first white space.
#include <stdio.h>
#include<conio.h>
int main ()
{
  char string[100];
  int count=0,i,k;//variables declaration
  printf ("enter string\n");
  scanf ("%[^\n]s", string); //reads till new line is encountered or untill new line is encountered
  for ( i = 0; string[i] != '\0'; i++) //loop execution till the null character is reached.
    {
      if (string[i] == ' ') //condition testing
{
  break; //exits the loop and variable i's last value is taken
}
    }
    for (k=i+1; string[k] != '\0'; k++) //loop execution till the null character is reached from location i+1.
  {
      count++;                         //goes for increment
  }
  printf ("total characte after first space=%d",count);

  getch();
}









-------------------------------
in codeblocks
------------------------------------------------------------
//WAP to count all characters after first white space.
#include <stdio.h>

int main ()
{
  char string[100];
  int count=0,i,k;//variables declaration
  printf ("enter string\n");
  scanf ("%[^\n]s", string); //reads till new line is encountered or untill new line is encountered
  for ( i = 0; string[i] != '\0'; i++) //loop execution till the null character is reached.
    {
      if (string[i] == ' ') //condition testing
{
  break; //exits the loop and variable i's last value is taken
}
    }
    for (k=i+1; string[k] != '\0'; k++) //loop execution till the null character is reached from location i+1.
  {
      count++;                         //goes for increment
  }
  printf ("total characte after first space=%d",count);

  return 0;
}

No comments:

Post a Comment