C :: Compare 2 Strings And Print Out 1 If Characters Match And 0 If Not

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


ADVERTISEMENT

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 View Related

C# :: How To Match Regex If Input Was Array Of Strings

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

C :: How To Print Characters But No String Just Array Of Characters

Mar 20, 2014

so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?

Code:

int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);

[Code]...

View 6 Replies View Related

C/C++ :: How To Put Characters To Array And Compare To File Input

Mar 17, 2015

I am trying to generate possible combinations of 4 lower case letters from aaaa - zzzz. The words will then be used against a file that contains encrypted passwords that each relate to a 4 lower case word. I have successfully generated the words. Now all i need to do is put the created words (aaaa, aaab, etc...) to an array so I can use crypt((array[i+1]), buff) and print the encrypted 4 letters that come from the file. I am having a lot of trouble complete this though.

New problems that are occurring

The main problem is in the all function and main. I'm not wanting to print the aaaa, aaab, aaac, etc to the screen but I want to put it in an char array so that i can compare each individually to each line from the file using crypt. How to put all 456976 combinations into an array, compare it to each line of code, and print the solutions to the screen.

File:

$1$6gMKIopE$I.zkP2EvrXHDmApzYoV.B.
$1$pkMKIcvE$WQfqzTNmcQr7fqsNq7K2p0
$1$0lMKIuvE$7mOnlu6RZ/cUFRBidK7PK.

Code:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

[Code]....

View 1 Replies View Related

C++ :: Compare Two Strings Of Numbers

Jan 4, 2014

I am trying to figure out how to go about comparing two strings of numbers. I have two files that both contain numbers 1-50, one file has multiple repeating numbers while the other one just has 1-50.

I want to compare the files and count how many of each number a occurred and make a chart with * next to the number. First I figured I would use the strings like an array and compare them using nested loops. Then I noticed I have single and double digit numbers. The numbers in the files are printed as:

1 44 5 34 4
2 22 7 55 4
...... etc

Compared too:
1
2
3
4
5
......
50

I thought about using string stream and converting the string to int but wouldn't it just be a huge number when set to the int variable? Then I thought about a array initialized with 1-50 and compared to the file but I still have the issue with single and double digit numbers.

My question is how can I just read one number at a time, either double or single digit?

View 11 Replies View Related

C++ :: Can't Compare Char Strings

Jun 13, 2013

I have two char* that have the same data in (hypothetically).

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "data", B;
B = Buff.at(0)

Where Split is a function that I made to split a string (Line in this case) into a char* vector, this string contains a line from a file. Line is char* too. The weird problem is when Buff data stored in its 0 position is given to B... because B is equal to A (hypothetically) but when this is compared to do certain functions they doesn't match!

Here an example:

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "map", B;
B = Buff.at(0) // Buff.at(0) should be "map" and is apparently "map"

[Code].....

NOTE: I didn't use switch to compare Cmd because I want it separately for easier debugging.

Is there something wrong with my codes?? or what happened here with those hex values before the string in my variables?

View 6 Replies View Related

C++ :: Comparing Char And Int - Output Match Or Does Not Match

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

C++ :: Rules To Compare Two Strings Object

Sep 1, 2014

In my book I have the following example : Code:

std::string str = "Hello";
std::string phrase = "Hello world";
std::string slang = "Hiya"; and i have these two rules to compare 2 strings object :

if two strings have different lenghts and if every character in the shorter string is equal to the corresponding character of the longer string, than the shorter string is less than the longer string.

if any characters at corresponding positions of two strings differ, then the result of the string comparison is the result of comparing the first character at wich the strings differ then my book says : if we apply the rules of the comparison we know that phrase is greater than str( ok i've understood this ) and that slang is greater than both slang and phrase ( why ?)

explain me rule number two ? in phrase and slang the characters differ and the first character that differ is not H so why my book says slang is bigger than phrase ?

View 3 Replies View Related

C++ :: Compare Two Strings To See Which Comes First In Alphabetical Order

Oct 14, 2013

How would you compare two strings in an if statement to determine which comes first in alphabetical order?

Try and keep it simple because i am currently new to the language

View 2 Replies View Related

C++ :: Compare 2 Dates From Strings / Char Or Int

Mar 16, 2014

i have been trying to compare a date format from SYSTEMTIME and a date from a text file(string).But its not working. I tried to change both to string(using osstringstream),char* and int(using sscanf) to do the comparison but with no luck. its pretty simple all i want to do is get the current system date and compare it with the date from the text file. Below is my code:

char szcurrentDate[MAX_PATH] = "";
char szdate_time[MAX_PATH];
SYSTEMTIME st;
GetLocalTime (&st);
GetDateFormat(LOCALE_USER_DEFAULT,NULL,&st,"yyyy-M-d ",szcurrentDate,MAX_PATH); //current system date
//std::ostringstream mm;

[code].....

note : i tried displaying just szcurrentDate and szdate_time they show the date exactly the same. in string,char* or int formats.

View 2 Replies View Related

C/C++ :: How To Compare Strings Ignoring Case

Oct 29, 2014

It should report whether or not, ignoring case, they are the same.

#include <stdio.h>
#include <string.h>
using namespace std;

[Code].....

View 1 Replies View Related

C :: How To Compare A String With A Set Of Strings That Have Been Stored In A File

May 5, 2014

I am trying to compare a string that i have entered with a set of strings that have already been stored in a file. I am using strcmp function but i am not getting the result.

Code:
printf("
Enter string:");
scanf("%s",&m);
ptr_file =fopen("abc.text","r");

[Code] .....

View 10 Replies View Related

Visual C++ :: Compare Two Strings To See Difference In Int Form

Apr 2, 2013

I want to compare two string, and want to see differeince in int form. For example,

Code:
string first_string="0002AE1";
string second_string="0002AE2";

How can i calculate difference between two string? It is obvious difference between above two string is 1/-1, but difference would be 1.

View 2 Replies View Related

Visual C++ :: Procedure To Compare 2 Strings With Specific Criteria?

Jul 10, 2013

Procedure to Compare 2 Strings with the following criteria

coding of the following function -

I have absolutely no clue where to start -

Given the following sets of numbers -

1154 1179 2154 2554 2484 2144 4515 1144 1517 4815 1481

Given the Index number of 1154

I want to search the numbers for the Index number of 1154

The search will return a True if I can find 3 or 4 same digits between the Index number and the 8 numbers

The search also have the following criteria -

meaning that -

1154 when compared to 1154 == true
1154 when compared to 1179 == false
1154 when compared to 2154 == true
1154 when compared to 2554 == false
1154 when compared to 2484 == false
1154 when compared to 2144 == false
1154 when compared to 4515 == true
1154 when compared to 1144 == true
1154 when compared to 1517 == true
1154 when compared to 4815 == true
1154 when compared to 1481 == true

the index number can also be of type - 1234, 1123, 1112, 1111

View 14 Replies View Related

C/C++ :: Print More Strings (the Strings May Contain Spaces)?

Feb 12, 2014

I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.

#include<stdio.h>
#include<conio.h>  
int main()

[Code]....

For instance :

Give the number of sentences : 3

First sentence : I like the website bytes.com
Second sentence : I like more the website bytes.com
Third sentence : bytes.com

After I compile the program it should print the first two sentences.

View 2 Replies View Related

C/C++ :: Compare Two Arrays And Print Out A List Of All Songs Without Repeating

Mar 11, 2014

I have two arrays:

const char *mymp3list[15] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15" };
const char *myFriendsmp3list[20] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15", "Song 16", "Song 17", "Song 18", "Song 19", "Song 20"};

And I want to compare the two arrays and print out a list of all the "songs" without repeating any.

I've figured out how to print the just the duplicates using:

for (int count = 0; count < SIZE1; count++){
for (int i = 0; i < SIZE2; i++){
if (mysonglist[count] == friendsonglist[i])
cout << mysonglist[count] << "";
}
}

But I'm stumped on how to print a full list containing no duplicates.

View 4 Replies View Related

C :: Cannot Print Characters In The End

Feb 7, 2014

I cant print the characters in the end.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *arquivo1,*arquivo2,*arquivo3;//files i will open//
char texto;//texto= character i will read.

[Code]...

View 5 Replies View Related

C++ :: Parsing Txt File - How To Chop Strings Into Meaningful Characters

Dec 2, 2013

Are there any examples how to parse a matrix:

Code:

const string ABC = "
A B C D
A 1 -1 2 14
B 0 -2 -4 8
C 6 2 2 3

" so if i have it as a string stream and then loop through each line like this:

Code:
istringstream in (ABC);
for (string line; getline(in, line); ){
vector<char> vec(line.begin(), line.end());
for (int i = 0; i< vec.size(); i++)
cout << vec[i] << "
";
}

I get my strings chopped into characters. but how to chop it into "meaningful" characters so that -1 is not - and 1. is there any quick way for that to happen ??

View 3 Replies View Related

C :: Structures With Consecutive Strings (array Of Characters) As Members

Sep 24, 2014

Code:
#include<stdio.h>
#include<string.h>

typedef struct test
{
char a[5];
char b[10];
}t;

[Code] ....

In Unix (HP-UX) and Linux, the output of above program will be:

t.a=Helloworld!

Instead of the value of t.a ,i.e, "Hello" only.

Why such output? And what is the trick here to print the only value of t.a.

View 1 Replies View Related

C :: Reading And Printing In A Specific Format Strings Of Characters And Integers

Feb 23, 2015

I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.

On to my question... How do I read multiple lines with both carecters and integers. for instance:

nissan 1996
toyota 1998
or more comples like
nissan gtr 1996
toyota markii 1998

I want to use
int year;
char make[10]; maybe need to use char make[10][10]; for an array i would guess.
char model[10]; optional for the extra data

but reproduce what i read in a different order. say...
1996 nissan
1998 toyota
vice the original format.

this is what I have tried.

Code: scanf("%s %s", &make,&year);

//The way I seen to read multiple lines was on here

scanf("%[^/t]", %make);

But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.

View 1 Replies View Related

C :: Print String With Escape Characters

Mar 7, 2013

is there any function to print a string with all the escape characters in it?

For example, instead of printing:
This is a string.

It would print:
This is a string.

Or in Windows:
This is a string.

I know that you can debug the code to find the variable contents, but is there any way to accomplish this with some standard library function?

View 6 Replies View Related

C++ :: Print ASCII Characters - Limit In For Loop

May 1, 2015

#include<iostream>
#include<conio.h>
using namespace std;
int main(void){
clrscr();

[Code] ....

I am trying to print ascii characters but problem is If i put a limit in for loop to 255 or more than 126 the output don't stop it keeps on going

I know there is another way to this program but what i want to know this why this happen in this logic....it doesn't happen if a<=125 or less then 125.

View 7 Replies View Related

C :: Print Multiple Characters To Same File Using Fprintf Function

Nov 5, 2014

I'm new to C and was wondering if it was possible to print multiple characters to the same file using the fprintf function provided in one of the C standard libraries?

View 1 Replies View Related

C++ :: Receive Integer X And Print Alternating Alphabetic Characters

Feb 6, 2015

Q1. Recursive function that receives an integer x and prints the alternating alphabetic characters.

Write a main function to test the function;

ENTER NUMBER : 4

A C E G

Q2. Define a void function that finds the smallest value in the array and number of its occurrences. Also, it finds the largest value in the array and number of its occurrences.

ENTER 4 NUMBERS:
1 12 5 41 41

THE BIGGEST IS 41 AND IT OCCURS 2 TIME
THE SMALLEST IS 1 AND IT OCCURS 1 TIME

View 17 Replies View Related

C :: Can't Get Strings To Print When Using For Loop

Mar 6, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

Code:

#include <stdio.h>
int main ()
{
/* variable definition: */

[Code].....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved