Gets() not declared in scope

#include
#include<string.h>
#include
#include
#include
using namespace std;
char fre(char* a)
{
int l=strlen(a);
//cout<<l;
int i, j, count[l-1]={0};
for(i=0; a[i]!=’\0’; i++)
{
for(j=0; j<l-1; j++)
if(a[j]==a[i]) count[i]++;

}

int pos=0, max=count[0];
for(i=0; i<l-1; i++)
if(max<count[i]) 
{
    max=count[i];
    pos=i;
}
//cout<<pos;
return a[pos];

}
int main() {
char* a;
gets(a);
if(strlen(a)>=1 && strlen(a)<=1000)
{
char r;
r=fre(a);
cout<<r;
}
return 0;
}

hey @Sukanya, what problem you are facing?
Also please share the code saved in Coding blocks ide.

please help with this problem

hey @Sukanya, can you elborate me the issue. Is it giving wrong answer or something else.

gets() is not working due to which i m not able to take input as a string.
This is the code:
#include
#include<string.h>
#include
#include
#include
using namespace std;
char fre(char* a)
{
int l=strlen(a);
cout<<l;
int i, j, count[l-1]={0};
for(i=0; a[i]!=’\0’; i++)
{
for(j=0; j<l-1; j++)
if(a[j]==a[i]) count[i]++;

}

int pos=0, max=count[0];
for(i=0; i<l-1; i++)
if(max<count[i]) 
{
    max=count[i];
    pos=i;
}
//cout<<pos;
return a[pos];

}
int main() {
char* a;
gets(a);
if(strlen(a)>=1 && strlen(a)<=1000)
{
char r;
r=fre(a);
cout<<r;
}
return 0;
}

hey @Sukanya, gets() need an character array as an argument,not the character pointer.
Please make these changes.
Consider this link to know more about gets()
http://www.cplusplus.com/reference/cstdio/gets/

its giving same error with char array also

hey @Sukanya, gets() is not removed from C++14 as per official website of C++ .com. You can use fgets instead of gets.

here is article from officail website. https://en.cppreference.com/w/cpp/io/c/gets

And please ask one topic in one doubt only.

hey @Sukanya , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved.

1 Like