C :: Making Program For Comparing Strings

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


ADVERTISEMENT

C++ :: Class Objects - Program Not Comparing Two Strings

Jun 20, 2013

I am having difficulty with class objects.

1. why my program won't actually compare the two strings.
2. why and where I am having a memory dump crash.

The following is my main.cpp, String.cpp, and the header file in that order.

#include <iostream>
using namespace std;
#include "GREEN_String.h"
void main () {
GREEN_StringStr1;
GREEN_StringStr2 ("AdrianGreen");

[Code] .....

View 5 Replies View Related

C++ :: Making Bar Graph By Comparing Two Vectors

Jan 5, 2014

I am trying to compare two vectors and make a bar graph. I have tried sorting it and pushing it into another vector but this issue is when I go to output it. My logic is wrong.

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iomanip>

int main(int argc, const char * argv[]) {

[Code] ....

Output

22 *
44 *
22 *
45 *
33 *
44 *
18 *
34 *
33 *
12 *
3 *
5 *
34 *
33 *
5 *
7 *
22 *
44 *
49 *
9 *
18 *

View 3 Replies View Related

C++ :: Comparing Two Strings With Strcmp

Jun 22, 2014

I have trouble comparing two strings with strcmp. The bold part of the code are the parts that are not working and i hope somebody can explain to me what i did wrong. Goal of the code is to compare a city name with the name of already created cities and when two of them match to creat a Street between them. Depending on the street pointer different streets can be created

my vector containing all already created cities (it seem to work)
std::vector<city*> citylist;//all cities

find city using strings and creating a road between them:

bool Map::add_street(Street *street, const string firsttown , const string secondtown) {
city* hilfs1=Map::find_city(erste);
city* hilfs2=Map::find_city( zweite);
if (hilfs1==NULL || hilfs2==NULL)
{return false ;} // Problem :both pointers are always NULL

[Code] ....

Here is also my implementation of the getname function :

std::string city::getname() {
return this->name;
}

View 2 Replies View Related

C/C++ :: Comparing Strings With Pointers

May 29, 2014

I have wrote the code below that compares to strings and sees if they are equals doesn't matter the order of the words . In the question we where asked not to use any library functions like the string functions in <string.h> and we have to do that all with pointers . I debugged my code and for some reason the first loop in the function keeps looping ...

#include<stdio.h>
int IsEqual(char* str1,char* str2);
#define SIZE 20
void main() {
char str1[SIZE]="my name is monaya",str2[SIZE]="name monaya is my";
if (IsEqual(str1,str2))

[Code] ......

View 4 Replies View Related

C++ :: Comparing Strings Against Static String?

May 20, 2014

I'm writing a code generator that produces a function from the strings to the ints. I'll be using the generated code as a "from string to enum" utility. For example:

Code: enum Color {
Red, Green, Blue, Banana
};
// The definition of colorFromString is generated somewhere.
Color colorFromString(const std::string & s);

[Code].....

The implementation of the generated code is a trie. I've seen implementations in the past (including the one at work that I'd like to replace).

Anyway, say you need to compare the region of the string

Code: const char s[] = "holiday"; from index 3 until before index 6 against the string "ida".

I can see two bits of code that my generator could produce. One is

Code: bool hasIda = std::equal(s + 3, s + 6, "ida"); and the other is
Code: bool hasIda = s[3] == 'i' && s[4] == 'd' && s[5] == 'a';

The existing code generator uses the latter method, claiming (I think) that the generated instructions are more efficient on some architectures. Is there any way to determine which is better generally, or do I have to examine the assembly produced on all target platforms?

View 4 Replies View Related

C++ :: Airport Reservation Program - Binary Files Comparing

Aug 18, 2014

I am working on a airport reservation program and i have run into a brick wall. i want to ask the user its name, gender, passport no, age, destination, and travel class and figure out the day and flight code of the flight which i have saved in a binary file. now every thing works fine except the code and the day.

The programs important section

the flight class Code:
class flights {
char code[9],location[21];
public:
void display();
char *retloc() //to get the Location

[Code] .....

View 13 Replies View Related

C++ :: Making Program Involving Pointers

Dec 9, 2014

Write following functions

makingArray: this function will return a double pointer which points to a double array and take one parameter- an integer variable which has a default argument of 5. The argument is the size of the integer array. when the function is called, the users input or default argument will be used for the size of the array. The function will initialize all elements of the array with the 'cin' object.

getTotal: this function will return a double and take two parameters- a double array, which can NOT be modified by this function, and an integer variable for a size of the array. This function will calculate the total of all elements then return a double number which is the total.

main: demonstrate functions( makingArray and getTotal) by calling them in a program

View 1 Replies View Related

C/C++ :: Making A Program That Gives All Primes Below A Given Number

Oct 8, 2014

I'm trying to understand why this won't work, the output i get is a list of even numbers. I'm trying to get all prime numbers below the number thats scanned in.

#include <stdio.h>
int isPrime(int number);
int main(){

[Code]....

View 5 Replies View Related

C :: Making Calculator Program Using Only Getchar And Putchar

Mar 21, 2014

I have to make a calculator program that has 5 different functions (this is obviously the easy part, once all the input is assigned to their respective variables), which are addition, subtraction, mod, multiplication and division (negatives are not allowed, and must be error-checked; spaces must be ignored). I need to take the equation from the user, echo it back and then solve the problem.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

[Code].....

View 4 Replies View Related

C/C++ :: Making Program That Solve Two Times Difference?

Oct 19, 2012

I need to make a program which solove difference between two interested times in format hh:mm i made it but it doesn't give me right answers for all times for example it can't solve times like 23:50 and 0:15 and it says that difference is 23:35 and no 00:25

View 3 Replies View Related

C++ :: Making A Program Read A Word In Backwards / Reverse?

Feb 26, 2014

Lets say I have my name "Kevin".

What would the program be so it reads "niveK"?

How to write the program for that?

View 4 Replies View Related

C :: Program That Does UNIX Strings

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

C++ :: Change Making Program Prints Correct Values But Prints Them In Loop

Jan 27, 2015

I have a program that makes change from an amount. It works fine, but the output is the correct output looped over and over. I have tried everything, but it still doesn't work. For example, a amount of 98 should print

3 quarters
2 dimes
0 nickles
3 pennies
but instead it prints
3 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies

Why it's doing this?

Code:
#include <iostream>
using namespace std;
int coinscount(int& amount, int value) {
int tracker = 0;
int amountdimes = amount;

[Code].....

View 3 Replies View Related

C :: Program To Move Strings From 1 File To Another

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

C++ :: Program To Read Several Strings From A File

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

C++ :: Program Doesn't Alphabetize Strings

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

C :: Program That Uses Tolower To Convert Strings Into Lowercase?

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

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 :: Program That Provides Number Of Utilities For Strings - Keep Getting Segmentation Fault

Nov 22, 2014

I'm working on a program that provides a number of utilities for strings, but I keep getting segmentation faults and I cannot tell why. strContains works fine, but basically the rest of my functions throw seg faults.

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"string_utils.h"

int strContains(const char * str,const char * subStr) {

[Code] ....

View 5 Replies View Related

Visual C++ :: Program That Take Strings From File And Push It Into Stack

Sep 29, 2013

How to write a programme that take strings from file and push it into the stack with number of each sting string before it and later clean the stack?

View 6 Replies View Related

C++ :: C Type Strings - Program To Ask User To Enter A String And Perform Functions

Oct 18, 2014

My assignment is : Please use C type strings ( array representation of strings). Write a program that will ask the user to enter a string. It will then regard that string as a worked-on string and allow the user to perform the following editing functions on it:

s – search
i – insert
a – append
d – delete
a – append
d – delete
r – replace
e – exit
s – search

This option will allow the user to search for a specified string in the worked-on string. If the string is

found, it will display the starting index (position) of the searched string in the worked-on string.

here is what i have so far.

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a_string[80];

[Code] .....

View 4 Replies View Related

C++ :: How To Append Strings To The Front Of Other Strings

Apr 7, 2013

I am programming a translator, and I have it so that it detects words with spaces both in front of and behind them, so I did "string.append(space);" where space equals " ". That added a space to the end, but I still need a space added to the front.

View 1 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 :: Comparing Password With Strcmp

Oct 7, 2013

I'm a novice with C programming and i have to solve an error in the following code. The code works like you enter a password called "uoc" and it shows as OK. But surprisely when you entered another password as "Cambridge" it works fine too.

I think that the problem is in the array declaration but i'm checking resources and no success!

Code:
#include <stdio.h>
#include <string.h>
struct {
char str[8];
char ok;
} data;

[Code] ......

View 3 Replies View Related

C :: Comparing Double To Integer

Feb 24, 2013

Given this code

Code:

double x=1.00,y=2,z=4;
if (y/z||++x)
x+=y/z;
printf("%f
",x); So (y/z||++x)

is true if at least one expression is true, that is either (y/z)!=0 or (++x)!=0 or both. I wonder how the comparison is done? Is (y/z) be truncated to integer or 0 be promoted to double?

View 2 Replies View Related







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