Ok , i am a baby in the world of C ++ ...
I have to write a code where takes string from user ,check for error (thru a function ) and return it to the main function ,everything using pointers . I am really stuck on it (it does not take my pointers to function )
What i am doing wrong ?? This is it:
#include <iostream>
#include <cstdlib>
using namespace std;
bool getstring (char*);
void main ()
{
char lenght[100];
int leng;
bool validata;
do
{
cout <<"Enter your name in lowercase :";
cin.getline (lenght,100);
leng=strlen(len ght);
validata= getstring(&leng ht);
if (validata)
{
cout <<"Enter your last name in lower case: \n";
cin.getline (lastname,100);
}
else
{
cout <<"Wrong input ...Try Again !!! \n";
}
}while (!validata);
}
// function to check valid data:
bool getstring (char buff[], *lenght)
{
int i;
char buf[100];
int *lenght;
bool noerrors = true;
cin.getline(buf ,100);
i=0;
while ((i< strlen(buf)) && noerrors)
{
if ((buf[i]<'a') || (buf [i]>'z'))
{
noerrors=false;
}
*lenght=strlen( buf);
i++;
}
return noerrors;
}
Any help will be really appreciated !!!!!
I have to write a code where takes string from user ,check for error (thru a function ) and return it to the main function ,everything using pointers . I am really stuck on it (it does not take my pointers to function )
What i am doing wrong ?? This is it:
#include <iostream>
#include <cstdlib>
using namespace std;
bool getstring (char*);
void main ()
{
char lenght[100];
int leng;
bool validata;
do
{
cout <<"Enter your name in lowercase :";
cin.getline (lenght,100);
leng=strlen(len ght);
validata= getstring(&leng ht);
if (validata)
{
cout <<"Enter your last name in lower case: \n";
cin.getline (lastname,100);
}
else
{
cout <<"Wrong input ...Try Again !!! \n";
}
}while (!validata);
}
// function to check valid data:
bool getstring (char buff[], *lenght)
{
int i;
char buf[100];
int *lenght;
bool noerrors = true;
cin.getline(buf ,100);
i=0;
while ((i< strlen(buf)) && noerrors)
{
if ((buf[i]<'a') || (buf [i]>'z'))
{
noerrors=false;
}
*lenght=strlen( buf);
i++;
}
return noerrors;
}
Any help will be really appreciated !!!!!
Comment