473,503 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with functions in c++

2 New Member
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;
}
Dec 12 '06 #1
2 1249
Coldfire
289 Contributor
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');
Dec 12 '06 #2
tommy3675
2 New Member
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
Dec 12 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1086
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...
4
1595
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.
57
4231
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
1
1323
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...
2
2510
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...
14
2897
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...
6
1630
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...
4
2442
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...
6
4519
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...
0
7084
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...
0
7328
jinu1996
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...
1
6991
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...
0
7458
tracyyun
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...
0
5578
agi2029
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,...
0
4672
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...
0
3167
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...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.