C :: Program To Match Strings From Input To Files Using Dfa
Sep 2, 2013
'Write a program to match the user input string with the contents of text files and give the result as to which files contain the input string. This has to be done by using finite automaton.' (Any language can be used) So basically, the user will input a string (in the command line or a gui) and "we must pass the text files to the DFA" (I'm double quoting this because it's precisely what my professor told) and then display those files which contain the string. The string can be hard-coded, ie,the user will get the output file that contains a specific string. ex: 'hello'. The problem is, I have never done any program on DFA so I'm at a loss. how to write the program. Should I read the files first and then use some 'switch' or 'goto' conditions for the DFA? Below is a code I found on the internet for simulating a DFA accepting a specific string.
Code:
s: accept = false; cin >> char;
if char = "m" goto m;
if char = EOF goto end;
goto s;
m: accept = false; cin >> char;
if char = "m" goto m;
if char = "a" goto a;
if char = EOF goto end;
goto s;
}
[code]....
View 3 Replies
ADVERTISEMENT
May 19, 2014
In the MSDN, it gives an example using Regex.Matches method:
using System;
using System.Text.RegularExpressions;
public class Example {
public static void Main() {
string pattern = "a*";
string input = "abaabb";
foreach (Match m in Regex.Matches(input, pattern))
Console.WriteLine("'{0}' found at index {1}.",
m.Value, m.Index);
[code]......
I am wondering if string input was an array of strings instead, how would I use Regex.Matches?
What I was thinking about doing is having the input array set to ToString(), input.ToString(), but that doesn't seem to work.
View 9 Replies
View Related
Oct 29, 2014
This program is supposed to compare 2 strings and print out a 1 if the characters match and a 0 if they dont. It compiles but doesnt give me the correct output.
Code:
#include <stdio.h>
#include <string.h>
void func();
int main () {
func();
return 0;
[Code] ....
View 11 Replies
View Related
Feb 21, 2013
My program compiles fine and doesn't have any errors so I am confused as to what the issue might be.
I have a int, which is determined by the user via cin.
I have a char, which is a random word generated from an input file.
1. I want the program to display "The word you entered does match..." if the word entered by the user is the same as the random word.
2. I want the program to display "The word you entered does not match..." if the word entered by the user is not the same as the random word.
The code I'm using for number one is
if (char == "int") cout << "does match..."
The code I'm using for number two is
else if (char != "int") cout << "does not match..."
Basically the programs only outputs "does not match" whether or not it really matches. Even if it matches, it outputs does not match.
Is something wrong with my code?
View 7 Replies
View Related
Nov 23, 2013
I am trying to make a simple program, I would like it to be able to do the following, Write a program that opens two text files (input1.txt and input2.txt) for input .The program should write the followings in the two files. input1.txt:
This is the first line in input1.txt.
This is the second line in input1.txt.
This is the third line in input1.txt.
This is the fourth line in input1.txt.
input2.txt:
This is the first line in input2.txt.
This is the second line in input2.txt.
This is the third line in input2.txt.
What would be the best way to go about doing this? I wrote the program below, but I don't think that it works.
#include <iostream>
#include <fstream>
#include <string>
int main()
{
using namespace std;
string input1;
[Code]...
View 2 Replies
View Related
Feb 15, 2013
We have an assignment to produce code to gather a string of input from the user in which they are entering a date. We then have to extract parts of that string to make substrings, and display different formats for the date(I will add my code in here so you can see what I have done). It took me a long while plucking away at this to understand this part. You will see that at the end of my code I have opened a file months.txt. We were provided with a file which states months corresponding to dates. I.e. 01January 02February 03March 04April, and so on until December. Exactly how I have typed it is how it is in the file.
I understand how to open and extract what is in the file as a string. I have extracted this as a string called myMonth (as you can see in the code as well) NOW,
I am supposed to have the program search for the month in the file, matching that to the month the user has input earlier, and then use the number infront of that month. I understand the basics of using find(), and making substrings. But how on earth do you get the computer to correlate what the user has input for a month, to finding that in the file, and then using the correct number.
Here is the code I have done so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string myDate; // Date input from user;
string myMonth; // Input from months.txt
[Code] ....
View 1 Replies
View Related
Mar 14, 2013
What is the best way to define const strings when there are separate header and source files?
For example, I have a header that only declare some enums. In that same header I would like to add string representations of those enums so that I can print them easily i.e string_representation[my_enum] for debug and error printing and so on.
If I define them in the header file, I will get a linker error for multiple definitions. If I remove the definition, then I can not define it in the source file.
View 13 Replies
View Related
Dec 27, 2012
I'm trying to calculate a series of times from start to end, and find out the duration between them, sum them up and see if they're above a certain value or not, for each particular instance.
My goal is to provide a prepared text file with time tags such as this:
Mon 19-Nov-2012 09:12 Mon 19-Nov-2012 09:34
Wed 21-Nov-2012 13:14Wed 21-Nov-2012 17:11
Fri 07-Dec-2012 15:21Fri 07-Dec-2012 15:26
=============================================
Mon 26-Nov-2012 12:50Tue 27-Nov-2012 15:29
Wed 12-Dec-2012 13:07Wed 12-Dec-2012 14:58
Fri 14-Dec-2012 14:22Fri 14-Dec-2012 14:29
And the program is able to calculate the total time relevant to each instance (instances separated by a line of '=').
Some form of number should somehow identify each instance or something similar and a text file is generated with total time printed for each instance. E.g.
Instance 1: 00h22m + 03h57m + 00h05m = 04h24m
Instance 2: 04h15m + 07h44m + 01h51m + 00h07m = 14h04m
Now I'm currently working on making the logic to calculate time within the ranges I'd like based on several parameters.
Are there any references I can use when it comes to working with strings in order to seek and extract these values in order to work with them? The documentation available on this website, despite being very informative, does not show practical applications of said class and I'm at a loss on how to implement the functionality.
View 17 Replies
View Related
Jan 20, 2014
In my project , we need to create an Array of Unicode Strings . The Array will contain 5000 Strings.
I need to write those strings to a text file which can be opened or edited with NotePad.
Normal _tfopen and fwrite are not able to create notepad compatible .txt file .. I mean the file I created is not readable with Notepad though file open mode is "w+t"
How can I save my unicode strings to a text file
View 6 Replies
View Related
Apr 5, 2013
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?
View 4 Replies
View Related
Apr 15, 2014
I am having a problem with my "void Validation :: getId()" function its suppose to get the id number from the user but when I try and type a letter to see if it catches it, it goes into this continuous loop. Also with my "string Validation :: getName(string name)" function it suppose to catch the comma in the user input for their last name , first name but doesn't catch it and still returns the name back to main function.
#include "InputValidation.h"
#include <iostream>
using namespace std;
Validation :: Validation() {
name = " ";
id = 0;
[Code] ....
View 1 Replies
View Related
Feb 19, 2014
I was very much confused with managing the 3d arrays. Other than initialising it is tough for me to input the data into the 3d array at runtime. I have tried the every possible method i know untill now but i can't successfully input and output the data.
I have written a code by declaring the 3d array of char s[5][2][20] in main and passing it's base address into another function, lets say input(char (*p)[2][20],int ,int ,int). I have passed the 3 dimensions in declaration 5,2,20 to the input function i have used these 3 values as the subscript for the pointer p and tried to input the data. But i wasn't successful.
How to input the strings into the 3d array.
My preferences were:
1.The change of subscript value should take place in loop(eg:for).
2.Which indexes should be used for inputing the data through pointer.
3.Use either "scanf" or "gets" function to inputs the data and print using "printf" or puts.
View 1 Replies
View Related
Apr 28, 2013
Assignment: Write a program that merges the numbers in two files and writes all the numbers into a third file. your program takes input from two different files and writes it output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to largest. after the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. your program should define a function that is called with the two input - file streams and the out - put file stream as three arguments.
Okay, here is my code.
#include<iostream>
#include<fstream>
using namespace std;
int main() {
int list1[25];//array for the first list
int list2[25];//array for the second list
[Code] .....
I'm confused about where the two files (which contain lists of numbers) need to be placed in order to be read and if they need to be renamed or something.
View 1 Replies
View Related
Nov 25, 2014
The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.
Here's my code:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);
[Code] ....
And I'm getting the error:
freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’
I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.
View 4 Replies
View Related
May 2, 2014
Write a program that opens two text files (input1.txt and input2.txt) for input and one for output (output.txt). The program should merge the two input files in the output files. While doing the merge, it will read one line from input1.txt and one line from input2.txt and write those in the output file one after other. Then it will read the next line from input1.txt and next line from input2.txt and write them one after other in the output file.
This is my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream myproject;
myproject.open("input1.txt");
[Code] .....
I need to:
1. how to get the second line in the input1.txt file and so on.
2. After the writing in output.txt, count the number of lines in output.txt.
3. write the number of times term ‘line’ appears in output.txt file.
View 3 Replies
View Related
May 18, 2014
My assignments asks for inputs of two files and then sorting them from small to largest in the third file. this is what I have so far. I am very lost... (first-time C++ student)
#include <iostream>
#include <fstream>
const int SIZE = 99;
using namespace std;
int main()
{
int num[SIZE], num1, temp, count =0;
ifstream fin2;
ifstream fin1;
[Code]...
View 5 Replies
View Related
Oct 15, 2014
I'm in a CIS 143 class which is Introduction to Programming using C++. We've been assigned a lab with little to no detail on how to do the things listed.
The purpose of this lab is to practice the file input and output concepts. For this lab you may assume that the input files exist and contain appropriate data inside of them.
Four separate text files* which contain the following lines, different for each file.
(*: This isn't on the lab, but don't worry about what the name, age, id, and major are. those can be random and I can just change them what they need to be)
Name
Age
Student ID Number
Major
Your program should ask the user which of the four input files they would like to open, and then read the contents from the file. Once the contents have been read in, it should output to both the screen and a file named "output.txt" the four values were read in, arranged as follows:
"Hello <name>! You are a <age> years old <major> student, and your ID number is <ID number>"
Now I am by no means saying "Do it for me". I just need to know how to have a user type file1, file2, file3, or file4, and then have the program open that file, then have the output.txt file arrange the wording into the sentence above.
This is what I have so far and I don't think it is anywhere near correct:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inFile;
string file1;
string file2;
[code]....
View 1 Replies
View Related
Aug 3, 2014
I am having an issue with the statement "Both the input and output files' names should be read from the command line." I don't understand what this means or what I need to do.
View 4 Replies
View Related
Jun 4, 2014
I am not a programmer, C-wise. Mainly a shell scripter. any C program that I can use that can work like UNIX strings | grep "pattern"...At the moment, on a binary file, I am using UNIX strings and then grep for a pattern and print out that line and does some awk -F":" thing. This is manageable for when the binary file is 50M but not for where files are 100M and above. I mean it still works but takes longer since strings work on the entire file.
Basically the information that I am trying to extract from the binary file is some type of header that is contained in a file. I am thinking of maybe writing a 'simple' C program that will read the first few bytes of the binary file and then print the line that contains the string that I am looking for. I don't believe the header is at the end of the file but more in the beginning. I am wanting to extract the header information to be able to rename or make a copy of the binary in a more user-friendly name.
Any good reference/link to a sample program on reading a binary file maybe. Main reason why I am wanting a C program is because the binary file can be on Windows or *nix.
View 2 Replies
View Related
Mar 5, 2013
My objectives for this program is to open and read a file "dict.txt" which has the following data:
4
dog
pepper
marker
teapot
It needs to rotate the inner letters one to the right so you'd end up with "mrkear" etc, and then write those words into a new file "scramble.txt" one per line.I'm having a lot of problems understanding the program. Compiling is giving me a lot of warnings/errors.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXW 10 //max number of words in file
#define MAXS 81 //max size of string
}
[code]....
View 2 Replies
View Related
Oct 16, 2013
I know there is a function for comparing string but i am making it to just improve my concepts.error : 2 is coming as answer when i put same sting in both place.
Code:
#include<stdio.h>
main()
{
char str1[] = "hello" ;
char str2[]= "hello" ;
int q;
q = xstrcmp(str1,str2);
printf("%d",q);
}
[code]....
View 5 Replies
View Related
Oct 11, 2013
Write a program that reads several strings from a file. Display the number of words then display each word as shown in the sample below. Assume that the maximum number of string in the file is 100.
Sample Input (.in):
Smitty
Werbenjagermanjensen.
He
was
number
1!
Sample Output:
Total Number of Words: 6
Word[0] = Smitty
Word[1] = Werbenjagermanjensen.
Word[2] = He
Word[3] = was
Word[4] = number
Word[5] = 1!
View 1 Replies
View Related
Jan 18, 2015
I can't seem to get my program to alphabetize a vector string. It displays the names, but not in a sorted order.
void sort_names(vector<string> &nameList) {
int i, minIndex;
string minValue;
int size;
size = nameList.size();
[Code] ....
View 4 Replies
View Related
May 13, 2014
say I have person 1 to person 1024
Let's say
I want to sort them from smartest to dumbest
I have very few data say
person 1 is smarter than person 23 and so on
There are many missing data
say I don't know if person 30 is smarter or dumber than person 50
How to sort this kind of array ?
I definitely know it can't be sorted but how can I sort this as best as possible.
View 4 Replies
View Related
Dec 4, 2014
In the code below there is some error, I think it is related with functions. It compiles properly but then it outputs only : "humanslife8.90145e+032"
#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;
void userInput(float HumanNumber, float SkeletonNumber, float AllHumanslife, float AllSkeltonslife, float SkeletonHealth, float HumanHealth);
void HumansTurn(int turn, float HumanAttack, float AllSkeletonslife, float HumanNumber, float HumanDamage, float SkeletonHealth, float SkeletonNumber);
[code].....
View 3 Replies
View Related
Oct 6, 2014
Any simple program that uses tolower to convert strings into lowercase? Or simply just the general syntax of tolower pls. Can find it in google.
View 5 Replies
View Related