Visual C++ :: Search Function - Ask User To Input Name And Brings Out Line From TXT File Containing Information
Dec 8, 2013
How to get this thing to work. All i need to do is ask user to input a name and then it brings out the line from the .txt file containing the information.
For example in my case I'm doing a member search function I'm required to ask user to input the name of the customer and then print out all the details (which consumes 1 text line in the .txt file)
Here is the code, This is the write to text file method (100% working)
I'm trying to make a program that will search for a line in a text file using a non default delimitor at the start of the line. An example line in the text file would be as follows:
F Mary Smyth, 19, United Kingdom
I have been able to use the find function to search for and return the 'F' character but would like it to then display the whole corresponding line. Is this possible with the find function?
I have to create a program that incorporates an array of structures in order to simply read input from the user and then reprint that information to the screen. This is a fairly simple problem, but the issue is that the professor requires that we solve it in a very specific way.
I must have three functions in total: one to receive input from the user, one to print the received values, and of course the main function which calls the other two. Also, the input and output functions must be defined using the following prototypes:
typedef struct// Component { float cost; int code; char name[30];
[Code] ....
I know that this problem could be easily solved by simply passing the entire 'comp' array to the inputData function, or passing a pointer to it, or having it return a pointer, but I am not allowed to do any of these things. I must use the function as defined by the prototype.
I'm supposed to add two new functions to an existing class that I've written early on: readData(ifstream&)and writeData(ofstream&).
The parameters of the program are: -Create three employee objects as shown, -Create an ofstream object and open a file. Choose any name for the file that you want. Do not ask the user for the file name. Pass just the file name as the parameter (no path) so that your program assumes the file to be in the same folder as your executable file. -Send messages to each of the three Employee objects to write themselves out to the file. -Close the file. ...
If I get writeData(ofstream&) function bit to work! for brevity I've cut all the functions of the class that arent necessary. Here's what I have so far:
Employee.h #pragma once #include<string> using namespace std;
[Code] ....
So I've tried a bunch of different ways to get my objects into the ofstream object to write them to the file, but I'm supposed to use the two new functions somehow...but I'm way lost.
I am trying to get my input from user in the same line with certain width between but my output is not in the same line. my third variable which is fruit[i] is shown one line below . How I can fix this ?
#include <iostream> using namespace std; int main () { int staff[3] , fruit[3];
The textfile babynames.txt, which is included in the books website, contains a list of the 1000 most popular baby names of boys and girls. Write a program that allows the user to input a name and the program should then read the file and search the matching names among the boys and the girls. If the name is found it should output the name and the names rank. It should also indicate if their is no match. How to start this.
On fairly rare occasions, when attempting to debug one of my MFC applications on VS 2010, a compilation error is encountered, and instead of bringing up the customary Windows or MFC file with a arrow pointing to the problem, a disassembly appears with an arrow pointing to one of the assembler instructions.
Since Windows assembly language is hardly my forte, I do not know how to interpret the error. Furthermore, the Output usually indicates one or more 'first chance exceptions' but little more, and the Stack output usually quite sparse and often refers cryptically to some ntdll.dll!7c92a82c().
I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.
Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.
Code:
#include <iostream> using namespace std; int main() { int input; int number; int row=0; int col=0; int Array [12][10];
I was trying to make a program in C that could take Personality Information from the user and store it in a text file. Then, when asked, could compare the results to other entries in the so called "data-base" and tell which is the best match. I tried a whole lot but couldn't think of a proper way.
(Stings and File IO are not my strong points)
I am using Code Blocks 10.05 and the standard GCC compiler.
I am having problems printing "->" on the beginning of each line, im trying to do it as a loop and ending it when the user types "q". also i would like to know how to ignore text from the user when the input begings with a specific character. heres what ive done so far, and not currrently working as expected.
Code: #include <stdio.h> int main (void) { char prompt; printf("~~~ FRACTION CALCULATOR ~~~
I have code that creates an index file created from a data file of records.
#include <iostream> #include <fstream> #include <map> #include <sstream> #include <string> #include <iomanip> using namespace std; class Record {
[Code]...
I now need to write a second program that allows the user to enter a command on the Linux command line such as
search 12382 prog5.idx
and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.
Here is the index file created by the first program:
I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:
Code: #include<iostream> #include<string> #include<fstream> #include<stdlib.h> #include <vector> using namespace std; int main(){ vector <string> words; string str, paieska;
I'm trying to read the data from a file i/o and put them into an array of structs. But when I run the program, it gives me a bunch of "garbage" as an output. my code and see
I want to be able to write a program where I can record user input but combine it with command line arguments. For example I do a simple getline(); and the user types test how to combine it so it could be like test /q and it gives a different output depending on what additional input was added. Can this be done with lots of different inputs?
im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.
I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.
I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.
My first user defined function is simple enough
Code: ReadArray(int A[], int size){ int i; printf("Please enter %d integer numbers separated by spaces: ", size); for (i = 0; i < size; i++) scanf("%d", &A[i]); }
Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.
I am confused as to my next function:
Code: void SearchArray(int A[], int target, int size);
I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?
If i call *A do i then use something like this for my search:
Code: for (*A = 0; *A < size; *A++) if (*A < target) or use A[] insteadA?
Code: for (i = 0; i < size; i++) if (A[i] = target)
I am writing a program that grabs information from a .dat file. I have the code all structured up, but I get these 2 errors that does not make any sense to me on how to fix the program.
errors (2):
Code: Error1error LNK2019: unresolved external symbol "void __cdecl swap(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *,class std::basic_string<char,struct std::char_traits<char>, class std::allocator<char> > *)"
How can I create in my C++ program so a user can paste a text and then choose a character on specific line and place?. The above thing isn't that important. I just want to place a character on a specific line and place.
I mean something like this:
Enter a character:
You choosed " / "
On which line do want the character?
You choosed "Line 1 and 2"
Where do you want the the to appear on the line? (left or right)
I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; //binary search function bool search (int array[], int item)
The program I have below. If you copy and paste it it should work. However, When I uncomment my search function I get lots of errors and I think it has to do with incorrect syntax of it being a template. Need to do this search function:
Linked.h header file
Code: #ifndef LINKED_H #define LINKED_H #include<iostream> template <class T> class Linked { private: // Declare a structure for the list
I am trying to use the command line to put a txt file in this code. I do Project->set project arguments in code blocks and nothing happens. How does one set up the arguments and where do i do it in codeblocks?
Code:
int main(int argc, char *argv[]) { char name[20]; struct artist *ptr; char lineBuffer[LINEBUFFERSIZE]; artistNodePtr startPtr = NULL; /* initially the artist list is empty */ FILE *musicFile; char *artistTemp, *discTemp, *yearTemp, *trackTemp, *songTemp;
I am unable to implement the insert function properly,every time i run the program i just get the first value and name,i am not getting other Id's and name.
Code: "(Header File)" #include <iostream> #include <string> using namespace std; class node { public: int ID; node (string StudentName, int IDNumber) {
This code is near complete, the only task that is left is allowing the user to input a decimal and then two integers, or automatically using .00 decimal.
The automatic part: /*This is not correct.
printf(".%.2d ", number); */
But that does no good for me. Question: Do I have to create a some sort of while loop again, to allow the user to input a decimal followed by integer?
Code: #include <iostream> #include <cstdlib> using namespace std; int main() { int j , i = 0, k = 0; int number;