0

a program wherein you input a 8 character string..and then validate if its a valid identifier..a valid identifier is a string that starts with an alphabet and underscore(_)..invalid identifier starts with a number and a double underscore(__)

4
Contributors
3
Replies
9
Views
8 Years
Discussion Span
Last Post by ZaiBo
0

for space how to declare it as an invalid this is my sample program and it will make the space valid.

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
int main ()
{
char input[50];
int i,l;
h:
printf("Enter an identifier:");
scanf("%s",input);
l=strlen(input);
    if (isalpha(input[0])){
    for(i=0;i<l;i++){
      if((input[i]=='+')||(input[i]=='-')||(input[i]==' ')||(input[i]=='=')||(input[i]=='"')
      ||(input[i]=='#')||(input[i]=='@')||(input[i]=='!')||(input[i]=='.')||(input[i]==')')||(input[i]=='(')||(input[i]=='*')){
      printf("Invalid!");
      break;
      }
      else if(i==l-1){
          printf("Valid!");
          }
        }
      }
    else{
    printf ("Invalid!");
    }
printf("\n");
goto h;
}

Edited by Nick Evan: Fixed formatting

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.