Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <stdio.h>
#include <ctype.h>
int main()
{
    int i,j;
    char a[20];
    fgets(a,50,stdin);
    int len=0;
    for(i=0;a[i]!='\0';i++){
        len++;
    }
    int k,g;
    for(k=0;k<len;k++){
      if(islower(a[k])){
        a[k]=toupper(a[k]);
      }
    }
    printf("%s\n",a);
    int v=0,c=0;
    for(g=0;g<len;g++){
      if(a[g]=='A'||a[g]=='E'||a[g]=='I'||a[g]=='O'||a[g]=='U'){
         v++;
      }else{
         c++;
    }
    printf("vowel-%d="" and="" consonants-%d",v,c);
    return 0;
}


What I have tried:

What I have tried:

My antivirus software defined that as (infected by Virus: Gen:Variant.Bulz.560818). I can't run this program.
Posted
Updated 6-May-22 7:09am
v3

Try adding some extra lines of code just to change the shape/size of the executable. Something like:
C++
// add this before main
void foobar()
{
    int nothing = 0;
    char* nobody = "John Doe";
}
 
Share this answer
 
Comments
CPallini 6-May-22 11:31am    
Discarded by the optimizer. :-D
Richard MacCutchan 6-May-22 11:37am    
I didn't say it was any use.
CPallini 6-May-22 11:46am    
If it is discarded, then, how can it change the shape or the size of the executable?
Richard MacCutchan 6-May-22 11:53am    
I have just tested it and the addition of that code changes the executable size.
CPallini 6-May-22 12:10pm    
Well, I just tested as well.
You are right, my bad. I'm used to GCC compiler for ARM MCUs, I suppose it is more aggressive on code size optimization.
Change your build options to alter optimizations - that may be enough to prevent a false positive. If so, contact the AV supplier and ask them to try and prevent that happening.

But ... I'd suggest that you start by checking your whole system with a different AV scanner first ...
 
Share this answer
 
The solutions tell how to deal with this. One thing I noticed were these lines :
C++
char a[20];
fgets(a,50,stdin);
You are telling fgets to accept more data than the array a can hold and that can result in unexpected behavior from your program.

A better way to deal with this is to define a value for the size of the buffer and use that with fgets. Here is how you can do that.
C++
#define BUFFER_SIZE 49
char a[ BUFFER_SIZE + 1 ];   // +1 to accommodate trailing null
fgets( a, BUFFER_SIZE, stdin );
Now your code will not accept more data than the array can contain.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900