hello
i'm a beginner in c++ and i don't alot about getline function or any others so i done something wrong but i don't now what.
if i enter to many letters in cin.getline(t_oseba.ime, '\n') the program goes crazy
i hope someone could help me
thanks
here is the code
#include <iostream.h>
struct oseba
{
char ime[200];
char priimek[200];
int starost;
};
void dodaj(oseba &t_oseba)
{
cout << "\nDodaj osebo" << endl;
cout << "Ime: ";
cin.ignore(100, '\n');
cin.getline(t_oseba.ime, '\n'); //problem is here
cout << "Priimek: ";
cin.getline(t_oseba.priimek, '\n'); //and here
cout << "Starost: ";
cin >> t_oseba.starost;
cin >> t_oseba.starost;
}
void nova(oseba nova_oseba[], int &N)
{
oseba t_oseba;
dodaj(t_oseba);
nova_oseba[N]=t_oseba;
N++;
}
void izpisi(oseba t_oseba[], int N)
{
for(int i=0; i<N; i++)
{
cout << endl << (i+1) <<". oseba: " << endl;
cout << "Ime: " << t_oseba[i].ime << endl;
cout << "Priimek: " << t_oseba[i].priimek << endl;
cout << "Starost: " << t_oseba[i].starost << endl;
}
}
int main()
{
int odg;
int N=0;
oseba tab_oseb[200];
do
{
cout << "\n1 - dodaj osebo" << endl; // here you choose 1 to enter the problem
//cout << "2 - uredi osebe" << endl;
//cout << "3 - izbrisi osebp" << endl;
cout << "4 - izpisi osebe" << endl;
cout << "0 - konec" << endl;
cout << "Izbira: ";
cin >> odg;
switch(odg)
{
case 1: nova(tab_oseb, N); break;
//case 2: pogoj(tab_oseb, N); break;
//case 3: brisi(tab_oseb, N); break;
case 4: izpisi(tab_oseb, N); break;
case 0: cout << "KONEC"; break;
}
}while(odg!=0);
return 0;
}
2 1249
hello
i'm a beginner in c++ and i don't alot about getline function or any others so i done something wrong but i don't now what.
if i enter to many letters in cin.getline(t_oseba.ime, '\n') the program goes crazy
i hope someone could help me
thanks
here is the code
cin.getline(t_oseba.ime, '\n'); //problem is here
}
getline takes 2 or 3 parameters....and u have missed the important parameter
getline( _Str, _Count,_Delim);
_Str
A string in which to write. In ur case it is "t_oseba.ime"
_Count
The number of characters to read from strbuf. In ur case it is none/junk value
_Delim
The character that should terminate the read if it is encountered before _Count. In ur case it is "\n"
u just need to add the count parameter............and that should be the maximum size of the array/string in ur case its 200 for both
so do this
cin.getline(t_oseba.ime, 200,'\n');
getline takes 2 or 3 parameters....and u have missed the important parameter
getline( _Str, _Count,_Delim);
_Str
A string in which to write. In ur case it is "t_oseba.ime"
_Count
The number of characters to read from strbuf. In ur case it is none/junk value
_Delim
The character that should terminate the read if it is encountered before _Count. In ur case it is "\n"
u just need to add the count parameter............and that should be the maximum size of the array/string in ur case its 200 for both
so do this
cin.getline(t_oseba.ime, 200,'\n');
Thanks
Now all works perfect
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: roger |
last post by:
I'm having difficulties invoking a user defined table function,
when passing to it a parameter that is the result of another
user defined function.
My functions are defined like so:
drop...
|
by: Merlin |
last post by:
Hi
Imagine the following classes (A class diagram will help)
BASE, A, B, C, D, E, F, G.
A, B, C, D, G inherit from BASE.
E, F inherit from D.
|
by: Xarky |
last post by:
Hi,
I am writing a linked list in the following way.
struct list
{
struct list *next;
char *mybuff;
};
|
by: ashutosh |
last post by:
hi,
i am making the dll for clamav antivirus libraray so that i can make
activex control for windows.
i complied the library successfully and make the Libclamav.dll file using
win32 Api...
|
by: Fernando Barsoba |
last post by:
Dear all,
I have been posting about a problem trying to encrypt certain data using
HMAC-SHA1 functions. I posted that my problem was solved, but
unfortunately, I was being overly optimistic. I...
| |
by: Christian Kaiser |
last post by:
We have a component that has no window. Well, no window in managed code - it
uses a DLL which itself uses a window, and this is our problem!
When the garbage collector runs and removes our...
|
by: cppnow |
last post by:
Hello. I have a strange conceptual problem I'm trying to think about.
I would like to build a library that allows the user to do the
following:
1) User defined types:
The user defines their...
|
by: r_ahimsa_m |
last post by:
Hello,
I am learning WWW technologies in Linux. I created index.html file which I
can browse with Firefox/Konqueror using URL
localhost/~robert/rozgloszenia/index.html. The page looks fine but...
|
by: pauldepstein |
last post by:
Let double NR( double x, double(*)(const double&) f ) be the
signature of a Newton-Raphson function NR.
Here, f is a function which returns a double and accepts a const
double&. The aim of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |