From 20676b840d925c68467a8fbeb7cde65126b61571 Mon Sep 17 00:00:00 2001 From: Shivaraj Shetty Date: Tue, 15 Oct 2024 09:23:35 +0530 Subject: [PATCH] Added C code to check validity of string --- C/stringValidity.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 C/stringValidity.c diff --git a/C/stringValidity.c b/C/stringValidity.c new file mode 100644 index 0000000..184d0e4 --- /dev/null +++ b/C/stringValidity.c @@ -0,0 +1,20 @@ +#include +void main(){ + char s[50]; + int count1,count2; + count1=0; + count2=0; + printf("Enter a string\n"); + scanf("%[^\n]s",s); + for(int i=0;s[i]!='\0';i++){ + if(s[i]==42) + count1++; + else if(s[i]==35) + count2++; + } + if(count1==count2) + printf("Valid String\n"); + else + printf("Invalid String\n"); + +} \ No newline at end of file