473,651 Members | 2,485 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_o seba.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_o seba.ime, '\n'); //problem is here
cout << "Priimek: ";
cin.getline(t_o seba.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 1257
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_o seba.ime, '\n') the program goes crazy

i hope someone could help me

thanks

here is the code
cin.getline(t_o seba.ime, '\n'); //problem is here


}
getline takes 2 or 3 parameters....a nd u have missed the important parameter

getline( _Str, _Count,_Delim);


_Str
A string in which to write. In ur case it is "t_oseba.im e"

_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_o seba.ime, 200,'\n');
Dec 12 '06 #2
tommy3675
2 New Member
getline takes 2 or 3 parameters....a nd u have missed the important parameter

getline( _Str, _Count,_Delim);


_Str
A string in which to write. In ur case it is "t_oseba.im e"

_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_o seba.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 function dbo.scalar_func go create function dbo.scalar_func() returns int
4
1604
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
4269
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
1
1329
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 project in debug mode. this dll file exports all the 21 function which is needed for clamscan.
2
2523
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 am really desperate now, because I havent' been able to locate the origin of the problem for a couple of days now.. PROBLEM: the message digest obtained differs each time I execute the code, but works perfectly when applying the "control", that...
14
2919
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 component (created dynamically by, say, a button click, and then not referenced any more), the GC runs in a different thread, which prohibits the DLL to destroy its window, resulting in a GPF when the WndProc of that window is called - the code is gone...
6
1636
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 own types as needed for their particular application and registers them with the library. class ClassA {};
4
2455
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 there's one strange problem: I have written some JavaScript code in functions.js file which seems to be ignored when called although I have JavaScript enabled in Firefox/Konqueror. For example in functions.js I have:
6
4538
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 the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7297
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.