I'm trying to find a < character in a document, get it's position. Then find > and get it's position. Then i want to delete all things between that but runtime is terminating my process so i don't know what to do.
I want to make a program that receives the number of lines and collumns of a matrix, a matrix of char, the number of pairs of coordinates and the coordinates. the program has to return the char (or chars) that are on those coordinates on the matrix.
Example:
receives 2 3 ABC DEF 2 1 1 1 2
returns
AB
this is how i tried to solve this problem:
Code: #include #define MAX 1000 int main() { int nlin, ncol; char mat[MAX][MAX]; int x[MAX], y[MAX]; int ncoords; int l, c, n;
/* receiving variables and storing matrix.*/
[Code] .....
For some reason that i can't seem to find, this solution is not right.
Write a function to read and display the contents of names and marks. You then ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student.
Next, sort the arrays, write them out and then ask the user for a name to search for. This time use the binarySearch to return -1 or an index. Display the student's name and mark if found.
void getNames(ifstream& inStream, string names[], int marks[], int numElts); int linearSearch(const string names[], int numElts,string who); int binarySearch(const string names[], int numElts,string who); void selectionSort(string names[], int marks[],int numElts); void displayData(const string names[], const int marks[], int numElts); [Code] ....
Now I have worked up some stuff in parts but I am so lost and confused with these specific requirements: Previous questions asked me to sort out a linear search, a binary search and
LINEAR SEARCH:
int searchList(int list[], int numElems, int value) { int index = 0; // Used as a subscript to search array int position = -1; // To record position of search value bool found = false; // Flag to indicate if value was found
The program then asks the user for a search string, which may contain white space. The program should search the file for every occurrence of the search string. When the string is found, the line that contains it should be displayed in the following format
nnnnn:Line Contents
That is the line number of the line, 5 columns wide, right justified, followed by a colon, followed by the contents of the line.
And this is what I've got so far:
Code: #include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; int main(int argc, char *argv[]) { ifstream inFile; string fileName,
[code]....
But this doesn't work. It prints everything in the file, not just the lines where the string is found.
I have one tab seperated file and i whish to change values in one column and then copy the entire row (including the changed value) into anothe file.
file :
Code: x y z sdfsdgnsdfgndfjgndfbsgdf x y z dkjfgdsbfvgsdfvg x y z ksdnfsdfbsdnfsdvjsdbvjsdjfnsdbfubsdfjsdbfuibsdfsdfujbsduf
the way i am doing it right now:
Code: while (fgets(line, sizeof line, list) != NULL){ result = sscanf(line, "%ld %ld %d %10000s", &one,& two, &three,string); if (results == 4){ // change three //print: one two three string } }
the problem is that the string in the file is of variable size and sometimes it is bigger then my char string[10001] array which then i need to resize and it gets messy. Is there a way to somehow , once identified first three numbers (and modified) just to read the rest on a character base and the print it character by character into a new file so that i can avoid string array completly.
I can't get c++ compilers to create or open files with a string input, even though the compiler accepts a file name in "quotes". How can I get this compiled (I am downloading a series of file names which I need to load into a consolidated file).
My coding (the commented line works, the string example does not).
//indirect file open example #include <iostream> #include <fstream> #include <string>
I am using the code below to write a single instance of object "Employee" to a file in Binary mode. The write part seems to work fine, however when I try to read the single employee object from the file into memory I get a double free or corruption error.
I think this has to do with the fact that I am using a string data member in the Employee class but I don't understand what is going wrong. I have read that strings can vary in length and use dynamic memory allocation but if I write a single employee object to a file with data member 'name' equal to "John", it should be the exact same size when I read it back in right?
The code below works with no issues when I omit the string data member. Why is that? Where is the memory for the string object being "double released" when I read the employee object back into memory from the file?
I am using Linux Mint 15, Eclipse June and GCC 4.7.3 with the -std=c++11 option.
Im trying to make a c++ program for a school project, and i need to store the information into binary files, but I'm having some problems trying to store a class with string members, for example:
class whatever{ protected: string name; public: (List of functions) }
But if I do that, my code just dont work when I write and read a binary file, but if I change the string to char array, for example:
class whatever{ protected: char name[20]; public: (List of functions) }
It works good, so I wanted to know if there's some way to store a class wiht strings in binary files, or what am I doing wrong?
I am having a slight issue with the strcmp function. I am comparing string data from two different files. I want the function to output a set of information if the strings are the same and a different set of data if the strings are different. My issue is, the function outputs the data that's the same but not different.
I had an else statement that compared the data if it was NOT equal but it only duplicated the data in the file.
One file is a listing of 100 books with 10 lines of information and an assigned market. The second file is a listing of the markets contained in the books file. However, the books file has a market that is not located in the markets file. The "missing" market is what is not priting or displaying.
I have an assignment to create an address book in c++ where you can enter contact information and then search all entries via last name. I am trouble figuring out how to write a function that will be able to search an entry by last name. Here is my code so far:
#include <iostream> using namespace::std; class addBook {
For action, if user enters action, it will output the bones involved with that action. For strengthening, if user enters location, it will output bones involved with that location. For dagnostic, if user enters bone, it will output location of bone and whether bone is deep/superficial.
WPF window I'm working on. I have a window that has a textbox to enter a name to search a database table for, and when the search button is clicked, the ID for that username will be returned to a separate textbox. The code I've written atm doesn't seem to be working, but it looks fine to me. Here's what I've got;
private void btn_SearchUsers_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(txtb_SearchName.Text)) { SqlConnection sqlCon = new SqlConnection(conStr);
[Code] .....
So, I have the value entered into the textbox to be searched for stored in a variable, I'm selecting the ID from the table when the name in the variable is found, storing the result in a DataTable, and then in my foreach loop, if I find the name (the name column being index 1 in the table), I set set the ID result textbox to equal the ID for that name (the ID column being index 0 in the table). I think the foreach part is what's throwing me off. Maybe the column stuff? My Users table is like;
I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.
The program is as follows:
Code:
#include <stdio.h> #include <stdlib.h> int main(void){ char hostfile[75], hiddenfile[75], hiddenFileName[15] ; printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: "); scanf("%75s", hostfile);
[Code]...
The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?
I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.
I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.
What is the best way to do this? Even an outline algorithm will work.
I'm trying to write function that finds wheter the searched word exists or not. The compiler gives warning. Where is my wrong ?
|21|warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast [enabled by default]|
Code:
#include <stdio.h> #include <string.h> int main () { int result; char arr[]="sakir emmim evde mi evde mi dedik lan"; int size=sizeof(arr)/sizeof(char); char key[20]; scanf("%s", &key);
I am trying to write a program to search a library file with the name of a book or author and return the books that match the searched string in some way. For instance, if I search "Develop" it should display Game Development Essentials(Novak) and Developing Games in Java(Brackeen) and tell me that 2 records were found. Currently, it shows all the records regardless of what i search for, even if it is jibberish. Am I missing something in my functions? should I include the code that accesses these functions?
//If the user chooses A or a int showBooksByAuthor (int count, string name) { char choice; int index = 0; }
I have a multimap with over 300k entries defined like so: std::multimap<std::string, std::string> filedata;
Using the following code and std::multimap::equal_range, I am able to successfully search for a word in the multimap and get needed data:
// Data with strings. data = std::vector<std::string>(); // Get iterators to matched pairs. std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> dat = filedata.equal_range(word); // Go through each matched pair and get needed info. for (std::multimap<std::string, std::string>::iterator iter = dat.first; iter != dat.second; iter++) { data.push_back(iter->second); }
Now, I would like to search the multimap using regular expressions (EX: std::regex("[a-z][a-e]h")). What is the fastest way to do this? Example code may look like:
std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> dat = filedata.equal_range_with_regex(std::regex("" + word + ""));. Pseudo-code / algorithms will be enough.
How do i search a csv file?. I have a table with 3 columns (Employee ID , salary ,grade ) If i will enter an Employee ID and it should return the salary and grade of that employee id.
Make an ordered array. Put a bunch of random numbers into it. Do 20 linear searches and 20 binary searches of that array. (Code for linear search and binary search are found in the book.)Print out how many elements were checked before the item is found
I'm not looking for answers as it is homework. However I don't understand what I'm doing. This course is being held online(no other options) and that's not how I learn so I'm struggling. From my understanding I have to make a templated ordered array (which I don't understand at all) and then do searches (which I also don't understand).
im trying to make a function that will take in a users ID and search a text file for that ID and if there is a match to print out the matched line and the following 3 lines that follow. so far i ahve the following code but i cant get that to work and i dont knwo how to do the rest.
//declaring a file variable FILE *fpcust; int line_num = 1;