C :: Strcmp Of 2 Multidimensional Arrays

Aug 6, 2014

I have used strcmp before on one dimensional arrays but not 2 dimensional arrays.The problem is that I have one 2d array that has text with some misspelled words and I have to compare it to another 2d array and if the word from the first array (misspelled word) is not in the 2nd array then I print it to the screen instead of correcting the spelling. Here is what I have so far:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int read_dic(char [], char [][20]);
int read_words(char [], char [][20]);
void typo_check(char *, char *);
}

[code]...

View 5 Replies


ADVERTISEMENT

C/C++ :: How To Use Multidimensional Arrays

Apr 10, 2014

I am trying to use multidimensional arrays. I have made a 9 by 3 array and I am trying to use it in my code. Now I am trying to print the content of a particular subscript on user demand but it is giving me some weird error. Everything seems ok to me. Heres my code

#include <stdio.h>
#include<Windows.h>
int main(void) {
double array1[9][3]={{1000.99, 2000.99, 3000.99}, {950.99, 800.99, 700.99},{850.99, 750.99, 600.99},{725.99, 625.99, 525.99},{650.99, 550.99, 450.99},{655.99,555.99,455.99},{350.99, 250.99,200.99},{325.99,225.99,175.99}, {300.99,150.99,100.99}};

[Code] ......

View 6 Replies View Related

C++ :: Multidimensional Character Arrays?

Jan 19, 2013

I'm trying to create Minesweeper and with 2D Multidimensional character Arrays, It doesnt appear like in a grid format i want it to.

#include<iostream>
#include<conio.h>
#include<string>
#include<cstdlib>
#include<ctime>

[Code]....

View 1 Replies View Related

C :: Multidimensional Arrays - Variable Sized Object Maybe Not Be Initialized?

Oct 30, 2013

I'm trying to get a full understanding of multidimensional arrays. When I try to initialize the array I get an error.

Code:

int Pick2(void) {
int pick = 2;
int limit = 0;

[Code].....

The error I get is "variable-sized object maybe not be initialized" with warnings messages pertaining the that Error message.

View 12 Replies View Related

C++ :: Multidimensional Arrays - Enter Data Into Table And Display On Screen In Tabular Form

Sep 8, 2014

Write a program to enter data into a table and display on the screen in tabular form. I want to know where are the errors.

#include<iostream>
using namespace std;
int main() {
int table[3][4];
int r,c,i;
r=c=0;
while(r<=2)

[Code] .....

View 3 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 :: Searching Word Using Strcmp

Nov 15, 2014

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);

[Code]...

View 6 Replies View Related

C :: Strcmp Return Value On Different Compilers

May 3, 2013

I'm having a problem with the strcmp return value. My compiler returns the correct value based on my research, but I tried to compile the code below on those online compilers and the result was 1.

My compiler gave me 10, which I consider to be the correct result according to strcmp - C++ Reference. So strcmp is not very portable?

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

int main(void) {
printf("Return value: %d
", strcmp("Rocks", "Rockie"));
return 0;
}

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 :: Strcmp Negative Value From User Input

Jul 24, 2014

I am studying c and I thought what would be better than using my pi to play with relays and c. I am used to PHP as a scripting lang and don' t do much programming. So I wrote this to use wirepi and ask the user "on or off" they type on or off and it does it. it does work but I know something is wrong when I use strcmp in the if statment I can -10 for a value. Here is the code.....

Code:
#include <stdio.h>
#include <string.h>
main(int argc, const char * argv[]) {
char oo[100];
system("gpio mode 0 out");
printf("Do you want it on or off?

[Code] ....

This is what it outputs at the prompt

Do you want it on or off?
on
on

It is now on!

How can I just get Code: if (oo = on) {} and like so with off.

View 2 Replies View Related

C++ :: Seller Array - Error When Trying To Use Strcmp Function

May 1, 2014

I'm having an error when trying to use the strcmp function. Here's the jist of the code I'm working with:

Code:
class Seller
{
public:
Seller();
Seller( char [], char[], char [], double );

[Code] ....

I'm getting a
"[Error] cannot convert 'Seller::getID' from type 'char* (Seller:: )()' to type 'const char*'"
on this line of code:
"if (strcmp(sellerArray[i].getID, sellerArray[j].getID) < 0) "

How do i have this method able to compare these values in my seller array? Granted, there is more to the code and things actually in the seller array at this point. Is there something I'm not seeing??

View 4 Replies View Related

C++ :: Boost Binding - Comparing String Using Strcmp

Jun 5, 2014

I am trying to compare strings (char*) using strcmp but I am having a hard time doing it with boost::bind. It compiles but it crashes when I run it.

I have a std::vector<boost::shared_ptr<DeviceInfo>> cMonitoredDevices and one cCurrentDevices. I used a typedef DeviceContainer for std::vector<boost::shared_ptr<DeviceInfo>>.

DeviceInfo is a simply struct that contains a char[128] Name (and other fields not important for this issue) that I want to use to compare.

So I am trying to find the DeviceInfo (based on Name) that are in cMonitoredDevice but not in cCurrentDevices. My problem is retrieving the Name value for the strcmp. Here is what I have so far

for(DeviceContainer::iterator pDevice = m_cMonitoredDevices.begin();
pDevice != m_cMonitoredDevices.end(); pDevice++) {
if (std::find_if(cCurrentDevices.begin(), cCurrentDevices.end(),
boost::bind(&strcmp, boost::bind(&boost::shared_ptr<DeviceInfo>::value_type::Name, _1),
(*pDevice)->Name) == 0) == m_cMonitoredDevices.end()) {
}
}

View 2 Replies View Related

C :: Passing Arg 1 Of Strcmp Makes Pointer From Integer Without Cast

Jan 18, 2015

Code:

#include <stdio.h>
int main(){
int a=15 ;
int b =20 ;
strcmp((a, "20") == 0) {
printf("Correct!");

[Code] .....

passing arg 1 of `strcmp' makes pointer from integer without a cast

View 11 Replies View Related

C++ :: Strcmp Function - Comparing String Data From Two Different Files

Dec 20, 2013

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.

// final project2 file

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

using namespace std;
const int ARRAY_SIZE = 500;
const int MARKET_ARRAY = 6;
ifstream infile, infile2;
ofstream outfile;

[Code] .....

View 6 Replies View Related

C++ :: Strcmp On Linked List Data And String Constants?

Sep 28, 2013

why strcmp() doesn't return true when comparing a string constant with a string that was acquired via a linked list. By the way, the data in the linked list was taken from a text file. Does that imply that there's a new line () character in the string from the linked list?

Code:
struct Node{
char ACNO[15];
struct Node *next;

[Code]....

View 1 Replies View Related

C++ :: Tic Tac Toe Game With Multidimensional Array

Jan 13, 2015

Problems :

1) Is there any way so that i can use "X" and "O" char instead of 9 and 0 int.?? I also tried to use enum but was only able to print out -1 for 'X' and 0 for 'O'...

2) if player - 1 choose field 2 . and player - 2 chooses field 2 .. how can i show error and ask for another input ?

3) is there any short coding trick for int check_result(); ?

Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

[Code] ....

View 3 Replies View Related

C :: Pointer To Multidimensional Array

Jul 31, 2014

What is the correct method of declaring pointer to multidimensional array

Code:
int array[3][4];
int *p = array;

The above code works but it shows warning. Is it an invalid way of using the pointer? the array is an address then why am i getting warning?

View 1 Replies View Related

C++ :: Passing A Multidimensional Array

Sep 25, 2013

I'm trying to pass a two-dimensional array to a function. The function is defined as: long foobar(char foo[][CONST]); I have to create that array dynamically. Currently I do that this way: char* bar = new char[count * CONST];

But when I'm trying to pass the array I get a type conversion error. I tried a lot of different ways to pass the pointer and/or to allocate the memory, but apparently I didn't find the right way or combination of definition, allocation, casting and calling.I cannot change the definition of the function, which (IMHO) is pretty stupid. :(

View 3 Replies View Related

C++ :: Error With Multidimensional Vector

Jun 22, 2013

I am having trouble accessing a one-dimensional vector as a multi-dimensional one.I have a MultiArray template class, and it is accessed using the function operator. It accesses elements through the expression row * m_columns + col. The row and col are the two inputs to the operator while the m_columns is the width/number of columns in the array. There is also a version that accesses the array with one number. Its underlying representation is a one-dimensional vector.The problem is when I try to load a level:

void Map::LoadFromFile(const std::string& filename) {
std::ifstream map_file(filename);
std::cout << m_map.GetHeight() << ", " << m_map.GetWidth() << std::endl;
std::cout << m_map_dimensions.y << ", " << m_map_dimensions.x << std::endl;
if(map_file.is_open())

[code].....

View 4 Replies View Related

C++ :: Assigning Multidimensional Vectors

Sep 28, 2013

I've seen code examples for assigning 2 dimensional vectors, but I haven't seen code for assigning more than that. I tried to create a 3 dimensional vector, and the only code the IDE didn't complain about was

int x = 2;
int y = 2;
int z = 2;
vector < vector < vector <string> > >stringvec;
stringvec.assign(x, vector <string>(y), vector <string>(z));

Would this be the correct way of producting a vector[2][2][2]?

View 5 Replies View Related

C++ :: Go Through Multidimensional Matrix Generically?

Mar 24, 2014

I have a doubt about how to go through a multidimensional matrix generically.

Examples of how to go through in particular cases:

-> 1 dimension:
unsigned int d0 = 3;
double m[d0];

[Code].....

How you can see, it is necesary so many for loops as matrix's dimensions.

I want to do an algorithm that go through a multidimensional matrix generically, that is, knowing the number of dimensions and the dimensions of one multidimensional matrix, go through all its elements. For example, it would be to implement this function:

/**
* Go through the multidimensional matrix given, assigning zero to all its elements
* @param dimensionsNumber The number of dimensions of the multidimensional matrix
* @param dimensions A pointer to the first element of one array of unsigned ints who size is the same as the number of dimensions given, so the ith element is the ith dimension of the multidimensional matrix
* @param multidimensionalMatrix A pointer to the first element of the multidimensional matrix
*/
void assignZeros(unsigned int dimensionsNumber,
unsigned int* dimensions,

[Code].....

View 7 Replies View Related

C++ :: How To Return A Multidimensional Array

May 1, 2015

I have put aside C++ for a while. And I am back to it.

I forgot how to return a 2 dimensional arrays from a method?

Code:
Node** GetNodeMap() const { return m_Nodes; }
private:
Node m_Nodes[60][60];

How can I achieve that?

View 5 Replies View Related

C++ :: Dynamically Allocating Multidimensional Array?

Nov 24, 2013

Working on this one from the Jumping into c++ book. The book asks that I create a multidimensional array at run time based on user input and fill it with a multiplication table

My code compiles fine but throws an uninitiated error for p when I try and run it.

Code:
void multiDimentionalMultiplication(int x, int y, int z){
int ***p;
**p = new int[x];
std::cout << "Allocating array.

[code]....

View 8 Replies View Related

C++ :: How To Get Number Of Elements Of Multidimensional Wstring

Jul 26, 2014

How to get the number of elements of a multi-dimensional wstring?

The usual char array way not working.

Code:

int main()
{
wstring wstr[][255] =
{
L"bbbb",
L"bbbb",
L"aaa",
L"ccccccc"
};
int Size = wstr.size() / wstr[0].length();
}

View 11 Replies View Related

C :: Scanning Characters Into A Multidimensional Array

Mar 19, 2014

I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"

The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?

View 4 Replies View Related

C :: Using A Pointer To Parse Multidimensional Array

Feb 27, 2015

I have a 3-dimensional matrix(3,3,3) and want to write it to a file. I have the code for parsing it in a compatible for matlab format. But at this point i want to use a pointer to do the same thing.

Code:

#include <stdio.h>
#include <stdlib.h>
int main() {
const int dimx = 3, dimy = 3;
int i, j;
unsigned char a[3][3][3] = {

[Code]...

If it is a 1-dimensional array i can understand the logic.

Code:

int val[7] = { 11, 22, 33, 44, 55, 66, 77 } ;
int *p;
p = val[0];
for ( int i = 0 ; i <= 6 ; i++ )

[Code]...

View 3 Replies View Related







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