473,785 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check my code please

Hi,
could someone please check my code? its asking the user to enter 3
letters, and check to see if these letters exist in the text file. i know
ive done something wrong. can someone fix my code please??

#include <fstream>
#include <string>
#include<iomani p>
#include <iostream>
#include<istrea m>
#include <cstdlib>
using namespace std;

int main()
{
char a, b, c;
ifstream myFile("data.tx t");

cout << "Enter the pattern you are searching for: ";
cin.getline >> a & b & c;

cout << "Program will now search for: " << a << b << c << endl;

return 0;

}

Jul 22 '05 #1
8 1767

"kittykat" <f_******@nospa m.hotmail.com> wrote in message
news:ad******** *************** *******@localho st.talkaboutpro gramming.com...
Hi,
could someone please check my code? its asking the user to enter 3
letters, and check to see if these letters exist in the text file. i know
ive done something wrong. can someone fix my code please??

#include <fstream>
#include <string>
#include<iomani p>
#include <iostream>
#include<istrea m>
#include <cstdlib>
using namespace std;

int main()
{
char a, b, c;
ifstream myFile("data.tx t");

cout << "Enter the pattern you are searching for: ";
cin.getline >> a & b & c;

What in the world does that do? Isn't the format for getline:
getline(cin,str ); ?
cout << "Program will now search for: " << a << b << c << endl;

Aren't you supposed to DO the search here???
return 0;

}


Is this some kind of joke? Trying to trick someone into doing your work for
you? Surely you don't expect us to think you don't see there isn't even one
line of code that searches in the text file for a match! At least TRY to do
your own work first. This is not an effort, it's just silly.

-Howard


Jul 22 '05 #2
kittykat wrote:
Hi,
could someone please check my code? its asking the user to enter 3
letters, and check to see if these letters exist in the text file. i know
ive done something wrong. can someone fix my code please??

#include <fstream>
#include <string>
#include<iomani p>
#include <iostream>
#include<istrea m>
#include <cstdlib>
using namespace std;

int main()
{
char a, b, c;
ifstream myFile("data.tx t");

cout << "Enter the pattern you are searching for: ";
cin.getline >> a & b & c;

cout << "Program will now search for: " << a << b << c << endl;

return 0;

}


have a look at this for some algorithms in pattern matching:

http://www.i.kyushu-u.ac.jp/~takeda/PM_DEMO/e.html

the naive algorithm should be easy enough to understand

greets

yoon
Jul 22 '05 #3
Thank you so much Yoon Soo!!! :)

Jul 22 '05 #4
Hi Howard,
this is my first week of trying anything in C++.

"Is this some kind of joke? Trying to trick someone into doing your work
for you?"

not a joke at all. i just wanted some help. my experience is very limited
and i am trying my best here.

"Isn't the format for getline: getline(cin,str );"

so in my case, would i write
getline(cin, a,b,c);
would that work?
Jul 22 '05 #5
kittykat wrote:
Could someone please check my code?
It's asking the user to enter 3 letters
and check to see if these letters exist in the text file.
I know [that] I've done something wrong.
Can someone fix my code please? expand kat.cc #include <fstream>
#include <string>
#include <iomanip>
#include <iostream>
#include <istream>
#include <cstdlib>
using namespace std;

int main(int argc, char* argv[]) {
char a, b, c;
ifstream myFile("data.tx t");

std::cout << "Enter the pattern you are searching for: ";
std::cin >> a >> b >> c;

std::cout << "Program will now search for: "
<< a << b << c << std::endl;

return EXIT_SUCCESS;
}
g++ -Wall -ansi -pedantic -o kat kat.cc
./kat

Enter the pattern you are searching for: a b c
Program will now search for: abc

Now write some code to search "data.txt" and post it here.
Jul 22 '05 #6
kittykat wrote:

Hi Howard,
this is my first week of trying anything in C++.
If this is true (and I don't doubt it)
then the assignment is much to hard for you (as for
anybody else with just one week of experience).

"Is this some kind of joke? Trying to trick someone into doing your work
for you?"

not a joke at all. i just wanted some help. my experience is very limited
and i am trying my best here.

"Isn't the format for getline: getline(cin,str );"

so in my case, would i write
getline(cin, a,b,c);
would that work?
No.
Which books are you learning from?

Read 3 characters: When we are allowed to ignore error checking
for the moment, it is written:

char a, b, c;

cin >> a >> b >> c;
Your version cannot work. Mostly because as you say for yourself:
"Isn't the format for getline: getline(cin,str );"
getline takes 2 arguments. You try to feed it
getline(cin, a,b,c);


4 arguments. 2 - 4. That won't work. Also: getline expects
a *string* variable. You don't have one. You have 3 char
variables.
char - stores a single character
string - stores a sequence of characters.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #7

"kittykat" <f_******@nospa m.hotmail.com> wrote in message
news:92******** *************** *******@localho st.talkaboutpro gramming.com...
Hi Howard,
this is my first week of trying anything in C++.

"Is this some kind of joke? Trying to trick someone into doing your work
for you?"

not a joke at all. i just wanted some help. my experience is very limited
and i am trying my best here.


Ok, sorry if I was harsh. But we see a lot of students here simply asking
us to do their work for them. And your post only said "something is wrong",
when it looks pretty obvious to me that the main problem is that there's no
code there at all that does what you're saying the program should do (which
is to match up the pattern with the text in the file). See what I mean? If
the problem you were having was a compiler error on the call to getline,
then you need to tell us, so that we can concentrate on fixing that.

-Howard
Jul 22 '05 #8
thanx so much. I am currently working on this, and will post it as soon as
i have finished. I have taken some advice from my previous "Pattern
Matching" post, and have decided to break the problem down into tiny bits.
once i have something completed, i will post it and see what you think.

Thanx so much once again for everyones help. i really appreciate it!

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3604
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers using check boxes. For example, a question such as
20
10163
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
5
2350
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
7
29939
by: Tony Johnson | last post by:
Can you make a check box very big? It seems like when you drag it bigger the little check is still the same size. Thank you, *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
7
2454
by: Neil | last post by:
I have a check box on a form that's bound to a function that returns a True/False value. When the user clicks on the check box, I run some code through the MouseDown event. Everything works fine. Only problem is: when the user clicks on it, there's a beep, and then they get a status bar message: "Control can't be edited; it's bound to the expression...." That's very annoying and disconcerting. Is there a way to trap the click and...
1
4266
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will require checking a check box to tell which category something will pertain to. Well after each record is entered i want the check to remain with that record and auto clear when going to the next record so i can input something else if i have a...
8
1931
mmarif4u
by: mmarif4u | last post by:
Hi everybody... I want to enter values to db like the following,,, Format is like this (810605-14-6356) This is the rite format, No a to z letters... 6 digits then - then 2 digits then - then 4 digits. dbConnect('db');
1
1420
by: icetalks | last post by:
have a look at this code , its for logging the user in after checking his UserName and Password. dim check as boolean = false ... ... If txtUserName.Text.Length = 0 And txtPass.Text.Length = 0 Then MessageBox.Show("please Enter Your Name and Password") txtUserName.Text = "" txtPass.Text = ""
12
4383
by: canabatz | last post by:
i got this php file 'check.php' that checks for changes ,and showing a counter for posts !! $show_data="SELECT * FROM bidding_main WHERE bid_id='$bid_id' "; $show_data_query=mysql_query($show_data); $num_show_data=mysql_num_rows($show_data_query); $sqlno="SELECT * FROM bidding_details WHERE bid_id=$bid_id "; $queryno=mysql_query($sqlno); echo "<table width='517' border='0' cellspacing='0' cellpadding='0'>"; echo " <tr>"; ...
0
9647
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...
1
10100
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
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...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.