Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

string checker

Posted by Circuit Negma on February 6, 2006


/*
 *
 *  datacheker.c
 *
 * this program is to check for the user input as only words and not numbers.
 *
 * by hussein, 2004
 *
 */
 
#include <stdio.h>

main()
{
      int i;
      char QQ;
      
      char address[200];
      char surname[220];
      char fullname[220];
      char Z[20], U[20];
      char X[20], Y[20], W[20];
      
      /*
       *
       * Checks for space in user input string.
       * note that %s will check for space. if there is a spce in the string 
       * the code will terminate at the last char. in the string.
       */
      
      printf("enter up to 19 chars no spaces for an array: ");
      scanf("%s", address);                // check for spce and terminate at that point.
      printf("\n\n");
      printf("Array Entered is:   %s\n\n", address);
      
      //------------------------------------------------------------------------
      while (1)
      {                               // check if the string is max. of 19 char.
        if (strlen(address) <= 19)
        {
                printf("there are %d chars. in your string.\n", strlen(address));
                printf("Array Entered is:   %s\n\n", address);
                break;
        }
        else
        {
            printf("\n\nenter up to 19 chars no spaces for an array: ");
            fflush(stdin);
            scanf("%s\n\n", address);
         }
       } 
      //------------------------------------------------------------------------  
      
      //------------------------------------------------------------------------
      for (i = 0; i< (strlen(address) - 1); i++)
      {
            if(address[i] == '') // '', it checks for space in string
                break;
            printf("%c", address[i]);
      }
      
      printf("\n\n");
      
      
      i = 0;
      while(address[i] != '')   // '', it checks for space in string
      {
            printf("%c", address[i]);
            i++;
      }
      //------------------------------------------------------------------------
      
       printf("\n**********************************************************\n"); 
      
      /*
       *
       * Checks for new line in the user input string.
       *
       */
        
       fflush(stdin);
       printf("\n\n");
       printf("enter up to 19 chars including spaces for an arry: ");
       scanf("%[^\n]", address);
       printf("\n");
       printf("Array Entered is:   %s\n\n", address);
       
       
       address[5] = '';
       
       printf("\n  ++ 1 ++ \n");
       fflush(stdin);
       getchar();
       
       
      i = 0;
      while(address[i] != '')   // '', it checks for space in string
      {
            printf("%c", address[i]);
            i++;
      }

       printf("\n**********************************************************\n");
       
       
      fflush(stdin);
      getchar();
      
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: