C++ :: Searching Char By Diagonal Not Only The Main

Mar 6, 2015

I have a problem with searching chars by diagonal not only the main, i have a chars in vector and I need to go though all possibilities (as shown in picture) the word has to be side/2 long so here i have 9, so word has to be 4 chars long how I need to do this?

View 2 Replies


ADVERTISEMENT

C :: Searching A String On Char Matrix

Apr 12, 2014

I want to make a program that receives the number of lines and collumns of a matrix, a matrix of char, the number of pairs of coordinates and the coordinates. the program has to return the char (or chars) that are on those coordinates on the matrix.

Example:

receives
2 3 ABC DEF 2 1 1 1 2

returns

AB

this is how i tried to solve this problem:

Code:
#include
#define MAX 1000
int main() {
int nlin, ncol;
char mat[MAX][MAX];
int x[MAX], y[MAX];
int ncoords;
int l, c, n;

/* receiving variables and storing matrix.*/

[Code] .....

For some reason that i can't seem to find, this solution is not right.

View 6 Replies View Related

C++ :: Returning Char Array To Main Function

May 15, 2014

I want to return a char array to the main() function, but its returning garbage value.

#include<stdio.h>
//#include<conio.h>
#include<string.h>
char* strtrmm();
int main() {
char str1[100],c1[100];

[Code] .....

View 5 Replies View Related

C :: Recursive Function For Diagonal Winnercheck?

Oct 31, 2014

I am trying to learn so much C as possible by my own. I have learned a bit already and made my first game. I made a tictactoe with a 3x3 board that works great. But now i want to make it a NxN-board. But the problem right now is my checkwinner-function. I really don't know how I should check the diagonal for winner in the for loop. Earlier I have checked the diagonal manually like you can see down there.

Code:

for (Row = 0; Row < BOARDSIZE; Row++) {
if ((game[Row][0] == 'X' && game[Row][1] == 'X' && game[Row][2] == 'X') ||
(game[0][Row] == 'X' && game[1][Row] == 'X' && game[2][Row] == 'X') ||
(game[0][0] == 'X' && game[1][1] == 'X' && game[2][2] == 'X') ||
(game[0][2] == 'X' && game[1][1] == 'X' && game[2][0] == 'X'))
return 1;

I think I need two foor-loops in each other too and need to check the spots in the board like 0,0, 0+1,1, 0+2,2. Is that even possible?

View 3 Replies View Related

C++ :: Creating Diagonal Pattern By Given Function

Nov 5, 2013

How to create a diagonal pattern by the given function

void diagonal(int size, char op)

The function takes in 2 arguments, size and op and displays a diagonal line of op char. for example, diagonal (5,#) will produce the following output.

#
#
#
#
#

View 4 Replies View Related

C# :: Printing All Values Above The Diagonal Line In 2D Array

Apr 11, 2014

I need to print all the values in a square 2d array that are above the diagonal line. So if I have this 6x6 array for instance:

{0,0,0,0,0,0},
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5}

I'd have to print the elements in italics. I've tried this:

for (i = 1; i < a.GetLength(0); i++) {
for (j = i-1; j >=0; j--)
Console.Write("{0,-2}", a[i, j]);
Console.WriteLine();
}

with the array mentioned above but for some reason it keeps printing the elements BELOW the line, when I need it to print those above it. I know that for arrays we usually start loops with a value of 0 but seeing as there should be nothing to print at [0,0] I started the loop at 1.

View 2 Replies View Related

C/C++ :: 2D Array For Printing Both Diagonal Elements Of Matrix

Jan 31, 2014

what if we want to print both the diagonal elements!!!!

View 1 Replies View Related

C++ :: Find Biggest Part Of Column Over Diagonal Of Matrix

Jan 23, 2013

How to find the biggest column of the matrix (higher of main diagonal) Here is the draft of code that i desighned/ Of cause it has a several mistake. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.

#include<iostream>
#include<conio.h>
#include<time.h>
using namespace std;

[Code]....

View 5 Replies View Related

C++ :: Searching By Last Name?

Oct 23, 2013

I have an assignment to create an address book in c++ where you can enter contact information and then search all entries via last name. I am trouble figuring out how to write a function that will be able to search an entry by last name. Here is my code so far:

#include <iostream>
using namespace::std;
class addBook {

[Code]....

View 1 Replies View Related

C++ :: Searching In CSV File?

Feb 6, 2013

My .csv file is like:

Bone,origin,deep/superficial,location, action.

with list of 38 bones.

This is my main.cpp:

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include "Action.h"
#include "Action.cpp"

[Code] .....

For action, if user enters action, it will output the bones involved with that action.
For strengthening, if user enters location, it will output bones involved with that location.
For dagnostic, if user enters bone, it will output location of bone and whether bone is deep/superficial.

How I could search in csv file for these.

View 11 Replies View Related

C# :: Searching DB For Value In Textbox (WPF)

Nov 3, 2014

WPF window I'm working on. I have a window that has a textbox to enter a name to search a database table for, and when the search button is clicked, the ID for that username will be returned to a separate textbox. The code I've written atm doesn't seem to be working, but it looks fine to me. Here's what I've got;

private void btn_SearchUsers_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(txtb_SearchName.Text))
{
SqlConnection sqlCon = new SqlConnection(conStr);

[Code] .....

So, I have the value entered into the textbox to be searched for stored in a variable, I'm selecting the ID from the table when the name in the variable is found, storing the result in a DataTable, and then in my foreach loop, if I find the name (the name column being index 1 in the table), I set set the ID result textbox to equal the ID for that name (the ID column being index 0 in the table). I think the foreach part is what's throwing me off. Maybe the column stuff? My Users table is like;

ID Name
1 John
2 Roger
3 Mike

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++ :: Functions Searching A Database

Aug 8, 2013

I am trying to write a program to search a library file with the name of a book or author and return the books that match the searched string in some way. For instance, if I search "Develop" it should display Game Development Essentials(Novak) and Developing Games in Java(Brackeen) and tell me that 2 records were found. Currently, it shows all the records regardless of what i search for, even if it is jibberish. Am I missing something in my functions? should I include the code that accesses these functions?

//If the user chooses A or a
int showBooksByAuthor (int count, string name)
{
char choice;
int index = 0;
}

[code]....

View 1 Replies View Related

C++ :: Searching For Line Intersections

Jul 26, 2013

I'm pretty decent at maths, and fair at programming but how I'd actually write mathematical line equations or check for intersections in script.

View 5 Replies View Related

C++ :: Searching A MultiMap With Regex

Apr 24, 2014

I have a multimap with over 300k entries defined like so: std::multimap<std::string, std::string> filedata;

Using the following code and std::multimap::equal_range, I am able to successfully search for a word in the multimap and get needed data:

// Data with strings.
data = std::vector<std::string>();
// Get iterators to matched pairs.
std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> dat = filedata.equal_range(word);
// Go through each matched pair and get needed info.
for (std::multimap<std::string, std::string>::iterator iter = dat.first; iter != dat.second; iter++) {
data.push_back(iter->second);
}

Now, I would like to search the multimap using regular expressions (EX: std::regex("[a-z][a-e]h")). What is the fastest way to do this? Example code may look like:

std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> dat = filedata.equal_range_with_regex(std::regex("" + word + ""));. Pseudo-code / algorithms will be enough.

View 2 Replies View Related

C++ :: Searching Files For A String

Jan 30, 2013

I have 80,675 Files, 8,213 SubFolders.

I would like to search each file for a string, which will be last name.

Matches string, outputs path/filename, either to screen or a output file.

I have done this to a single file but never to multiple files and folders.

View 2 Replies View Related

C++ :: Searching / Reading CSV File

Jan 29, 2014

How do i search a csv file?. I have a table with 3 columns (Employee ID , salary ,grade ) If i will enter an Employee ID and it should return the salary and grade of that employee id.

View 2 Replies View Related

C++ :: Searching An Ordered List

Oct 3, 2013

Make an ordered array. Put a bunch of random numbers into it. Do 20 linear searches and 20 binary searches of that array. (Code for linear search and binary search are found in the book.)Print out how many elements were checked before the item is found

I'm not looking for answers as it is homework. However I don't understand what I'm doing. This course is being held online(no other options) and that's not how I learn so I'm struggling. From my understanding I have to make a templated ordered array (which I don't understand at all) and then do searches (which I also don't understand).

View 1 Replies View Related

C++ :: Searching A Text File?

Apr 23, 2013

im trying to make a function that will take in a users ID and search a text file for that ID and if there is a match to print out the matched line and the following 3 lines that follow. so far i ahve the following code but i cant get that to work and i dont knwo how to do the rest.

//declaring a file variable
FILE *fpcust;
int line_num = 1;

[Code].....

View 3 Replies View Related

C++ :: Binary Searching By A Key Containing Two Variables?

Nov 24, 2014

So I have an array of distinct pairs of natural numbers. That is, my array looks something like this (for instance):

{ (1,5) , (6,4), (5,3), (2,3), (2,4) }

And my task is, for a given pair (a,b) find (if it exists) the pair (c,d) which has c > a and d > b and, in addition, is the "minimal" such pair (that is, c is minimal and, if there are multiple pairs which satisfy this with the same c, then d is minimal.

So for instance, if I run the query for the above array for pair (1,1), it should return (2,3) and if I feed it (5,2) it should return (6,4).

Now the problem is that I have to run multiple queries so linear time is not good enough. And my question is: is there any way in / any law by which I can "sort" such an array so that I can later run binary searches on it to find my answer?

I was thinking I could simply go like this: let (x1,y1) and (x2,y2) be two pairs to compare. Then:

if(x1<x2)
//pair 1 is smaller
else if(x1==x2 && y1<y2)
//pair 1 is smaller
else
//pair 2 is smaller

This seemed to solve most cases, however.. if I have an array which looks like this:

{ .... (50,60) ..... }

where (50, 60) is at the middle of the array. And I run a query for (40,70) for instance. The problem is that the pair that I want to find could be either on the left or on the right of (50,60) (we could have something like (45,90) on the right of (50, 60), but then again we could only have (x,10) on the left of (50,60) where x<50 so no pair on the left would satisfy our condition and I'd have to look to the right).

So to sum it up, if I'm running a query for pair (x1,y1) and through my binary search I come across and element (x2,y2) which has x1<x2 and y1>=y2, then my algorithm cannot decide whether it should keep searching left or right. So I have to search both sides and in a worst case scenario this ends up being O(n).

View 7 Replies View Related

C++ :: Searching Vector With Maps?

Sep 19, 2014

Currently im creating a simple phone directory. I am having a problem when searching the vector. It only lets me search for the exact key in the directory when I need to to search for strings that are close to the name. For example when I search "car" it will state that its not in the directory when it should pull up Carr, Derek and Carr David.

#include <string>
#include <map>
#include <vector>
#include <ostream>
#include <iostream>
int main() {
std::map<std::string, std::vector <std::string> > directory;

[code]....

View 1 Replies View Related

C++ :: Searching For Character In String

Jun 19, 2013

I'm trying to find a < character in a document, get it's position. Then find > and get it's position. Then i want to delete all things between that but runtime is terminating my process so i don't know what to do.

The code:

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

[Code].....

View 6 Replies View Related

C++ :: Searching A List Of Vectors?

Apr 30, 2013

How would you search through the a list of vectors? I have a upper case letter at the start of the lists and corresponding lower case letters in vectors how would I search through it to see how many times the corresponding lower case letter was repeated?

View 1 Replies View Related

C++ :: Searching A Number In Int Array?

Oct 12, 2013

Basically I initialize an int array of size 10 with zeros. Then element 7 is changed to 1. Via cin I collect a user input (integer) which is the number to be searched.

Now the problem is that the search function from the book is somehow not working. I added a function to see how the array looks like and there is definitely one element with value 1 that should be found, but it simply isn't. The function always returns -1 (element not found).

The program compiles, but doesn't work as it is supposed to.

//********************************************************
// search algorithm for arrays
//********************************************************
#include <iostream>
using namespace std;

[Code].....

View 5 Replies View Related

C/C++ :: Searching A Binary Tree?

Mar 1, 2015

I've almost got my code working. My issue is, if I type in either one of the first two id numbers, it finds the person and displays as it's supposed to, however if I type any of the last 6 id numbers it says id not found. I've been staring at this forever and can't see what I'm missing />/> ps, I haven't added in all my comments yet Binary tree template

//Binray tree template class
#ifndef BINARYTREE_H
#define BINARYTREE_H

[Code].....

View 14 Replies View Related

C++ :: Searching For Errors Within A Code

Dec 17, 2014

i use cygwin and i have a program that was returning an error saying "undefined reference" and i figured out that i misspelled a word. how can i search for the misspelling in the input mode, if ive just completed a very large program and dont want to scroll through possibly 300+ lines of input? im not totally out the loop, but i know i can "vim program.cpp" to open the program, but before clicking "i" to actually edit, there must be a way to search a word

View 9 Replies View Related







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