C :: Comparing Pointer And Integers?

Mar 25, 2013

I am trying to make a game where you have a secret code that is coded with colors like ROYG (red,orange,yellow,green) and I am having trouble when it tells you when you have a right color in the right spot or a right color in the wrong spot when you guess a color. How can I change my code under the function int comparearray where it will compare pointers to pointers and not integers and give me the correct number of "almost" and "correct".

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 100
#define COLS 4
}

[code]....

View 4 Replies


ADVERTISEMENT

C/C++ :: Comparing Pointer To Variable As While Loop Condition

Aug 11, 2014

I'm writing a delete function for a linked list, and I'm having issues with this bit of code:

void deleteNode(int data){
node* del = NULL;
t = h;
n = h;
while(n != NULL && n->_data != data){
t = n;
n = n->next;
}
}

Or more precisely, this portion:

&& n->_data != data

n is my new node variable, _data is the storage variable in the private section of my class, and data is the information being searched for that needs to be deleted. Everything works without this section of the code. My assumption is that n->_data is somehow wrong, but I don't see how. I've tried everything I can think of- using parenthesis, using the variable rather than the pointer, I've tried expressing the pointer in a different way, I've tried using my t variable rather than n, and I've found examples online that use this exact same expression without any issues.

View 2 Replies View Related

C++ :: Size Of Char Array - Comparing Name To Another One (Pointer)

Jul 13, 2013

I have function that looks like this myfoo(char* Name) Now i want to compare this name to another one . But the another name is a pointer . This my code :

bool Tribe::RemoveSurvavior(char *H_Name) {
const char *p;
p=SurpointArr[i]->GetSurvivor_Name();
}

I need to compare if p is same as H_Name.

Mine is do it with for on each element but when i use sizeof it gives me size of char and not real size of the name.

View 6 Replies View Related

C++ :: Read Set Of Integers Then Find And Print Sum Of Even And Odd Integers

Apr 21, 2014

I'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?

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

C :: Comparing Each Element Of One Array With Another

Mar 6, 2015

how to compare each element of array with another,defined ? I have tried this,but didn't work.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void bill()

[Code].....

View 3 Replies View Related

C :: Comparing Character To A Number

May 5, 2013

I created a function to check whether the first character of a string is a number or not by comparing it to every base 10 digit using a for loop. If it is, the string is valid, if it is not, the string is not valid

Code:
//ensure the first character is not a number
int ValidFirstChar(char FirstChar) {
int IsChar = TRUE, DigitCount = 0; /*boolean value indicating whether the first character is a number or not.*/

//check through all base 10 digits
for (DigitCount = 0; DigitCount <= 9; DigitCount++) {
if ((int)FirstChar == DigitCount)

[Code] ....

I have checked for the case where the first character is a number but it is displaying the error message for it. I have tried typecasting the char variable but that has not worked.

View 2 Replies View Related

C :: Comparing Two Dates Using A Structure

Jul 23, 2013

my problem is naming the function larger() with "int". At least that is what my compiler is leading me to believe.

Code:

#include <stdio.h>
struct Date{
int month;
int day;
int year;
};

[code]....

View 8 Replies View Related

C++ :: Comparing Two Floats Ranges?

Dec 24, 2014

I'm trying to compare two float ranges and it seems to be a hit and miss. I'm trying to use a object origin and dimensions comparing it to another set for collisions.

View 12 Replies View Related

C++ :: Comparing Arrays To Have Same Elements

Sep 2, 2014

If I have 2 arrays, say array1 = {2, 2, 4, 5, 6} which has sorted array elements and array2 = {4, 2, 6, 2, 5} that has same elements as array1 but not in sorted condition. How can I compare that both arrays have same elements. I have written the following code which works in all conditions except when array1 has two same elements and array2 has all different elements.

counter=0;
for (i=0; i<5; i++) {
for (int j=0; j<5; j++)
if (array2[i] == array1[j]) {
counter++;
array1[j]=0;

[Code] ....

View 7 Replies View Related

C++ :: Comparing Chars In A While Statement

Jul 1, 2014

I am trying to do this but it can never seem to work.

#include <iostream>
using namespace std;
int main () {
char charOne;
cin.get(charOne);
cin.ignore(1000, '

[Code] .....

Basically i want to keep looping until i enter an a or A (also does this apply to if statements as well?)

View 6 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++ :: Comparing Value To Array And Outputting

Feb 6, 2013

i have 3 arrays total, 2 of them i am comparing to see if any of the values match at all, and then i am putting the value that matches into the 3rd array. currently i am trying

int isthere (int match[], int maxmatchLength,
const int vec1[], int vec1Length,
const int vec2[], int vec2Length)
{
for (i=0; i<vec1Length; i++)
if vec1[i]==vec2[i];
vec1[i] = match[i];
}

But this will just match the same values are in the same spot. how do i fix it so that it compares one value in the first array to the whole second array, before going to the next number.

View 1 Replies View Related

C++ :: Comparing Two String In If Statement

Aug 31, 2014

i actually i want store string in r and try to compare other string (room_no) in function check but i try many time it still having error

#include<iostream>
#include<conio.h>
#include<fstream>

[Code].....

View 2 Replies View Related

C++ :: BST Comparing Parents To The Root

Mar 18, 2014

Lets say for example I have a BST that is sorted by char names, using strcmp. IF greater than 0 go right else go left.

I.E (this is just an example, they are not inserted correctly)

cat
/
dog buffalo
/ /
fish mouse zebra snake

I wanted to make a copy of this BST IF the length of the nodes are greater than the root, how would I approach this? I kinda started on this but I'm not sure if I'm making this more difficult than it should be.

void BST::copygreater(node * root, node *& dest, int & holder) {
if(!root) {
dest = NULL;
return;
}

holder = strlen(root->name) + 1; //Don't know about this? If we do a recursive call then the value would change every call?

[Code] ......

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/C++ :: Comparing 2D Char Array?

Jun 22, 2014

I am working on a program to find uppercase, lowercase and digits in a 2D char array. When I try to use an if statement to increase the counter, I get an error "no conversion from 'int' to 'char*'". This is the if statement I am using.

if(myArray[j] <='9' || myArray[j] >='0')

View 7 Replies View Related

C/C++ :: Comparing Two Arrays For Same Elements

Feb 17, 2015

int result = 1;
for (int j=0;j<N;j++) {
bool found = false;
for (int i=0;i<N && !found;i++) {
if (a[j] == b[i]) found = true;
}
if (!found) return 0;
}

I need to create a code that compares two in arrays without sorting them. They have to be the same length and contain the same elements in any order.

every integer in a[] is also in b[]
every integer in b[] is also in a[]
all such common values appear exactly the same number of times in both a[] and b[]

EX: a = {1, 2, 3}, b = {2, 3, 4} return 0 a = {1, 2, 3}; b = {2, 3, 1} return 1 a = {1, 2, 2}; b = {2, 2, 1} return 1 a = {1, 2, 2}; b = {2, 1, 1} return 0 a = {1, 1, 2, 2, 2}; b = {2, 1, 2, 1, 2} return 1

This is all i have...

View 8 Replies View Related

C++ :: Comparing Two Data Files?

Feb 15, 2013

I'm trying to compare two data files character by character to see if they are the same. If the files are different, the program should print out the line numbers of where they do not match. So far, I have the part where it returns 'T' for when the files are the same and 'F' when they are not. But how should I start where the program prints out the line number where the characters are different? I am thinking of an array but nor sure how to start it.

View 1 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 :: Comparing Structures From Binary File?

Jul 20, 2014

I'm wondering which method faster in comparing structures from a binary file.

Method 1:
Reading through the file one structure and a time and comparing each structure.

Method 2:
Reading numerous structures and allocating to memory , then reading through each allocated memory and comparing.

View 3 Replies View Related

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

C++ :: Floating Point Representation - Comparing With Zero

Nov 1, 2014

I'm currently trying to learn about floating point representation in depth, so I played around a bit. While doing so, I stumbled on some strange behaviour; I can't really work out what's happening...

#include <iostream>
#include <cmath>
using namespace std;
int main(){
float minVal = pow(2,-149); // set to smallest float possible
float nextCheck = ((float)((minVal/2.0f))); // divide by two

[Code] ....

Essentially what's happening is:
- I set minVal to be the smallest float that can be represented using single precision
- Dividing by 2 should yield 0 -- we're at the minimum
- Indeed, isZero2 does return true, but isZero returns false.

What's going on -- I would have thought them to be identical? Is the compiler trying to be clever, saying that dividing any number cannot possibly yield zero?

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 Words From Two Different Files Using Fstream

Feb 2, 2013

I'm trying to input a html file and copy everything from that file to a new html file with some changes. I need to read the html file word by word and compare them to a file with some keywords. If a keyword matches a word in the html file then it will add italic tags around that word in the output html file. As it is now it doesn't output anything.

Logically I want to read a word from the html file and then compare it to every keyword and output the result.

fileIn = original html file
keyword = keywords file
outFile = html file writing to
std::string str;
std:: string word;

[Code]...

View 2 Replies View Related







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