C :: Printing A String On A Char Matrix
May 27, 2014
So I have an array of char called s.This array has many words inside, each one separated by ''.The words are sorted by length (from bigger to smaller).I have have a char matrix with random things inside (it was not initialized) caled mat.I want to copy the first word from the array s to the matrix mat.
Code:
int nlin, ncol; /*number of lines and collumns.*/
int c,l,a,q;
char mat [1000][1000];
char s[1000];
}
[code]....
I can't see where this is wrong, but, when i test it, it clearly is not right. for example, if the input is 3 lines and 3 columns for the matrix and the word is crate, the output is :
cra
t
e
but it should be:
cra
t
e
View 11 Replies
ADVERTISEMENT
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
Jan 3, 2015
I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.
the function looks like this:
Code:
int printUser(){
printf("Following patients have been recorded in this session:
");
struct database patient1;
struct database patient2;
struct database patient3;
[Code]...
the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):
View 7 Replies
View Related
Feb 18, 2013
I need getting my initializer to work for my project. I get a segmentation fault when I try to print out what I've done.
#include <iostream>
struct matrix {
protected:
double * * data;
int rows, columns, size;
[Code] ......
View 3 Replies
View Related
Jan 31, 2014
what if we want to print both the diagonal elements!!!!
View 1 Replies
View Related
Aug 24, 2013
these are the errors that I'm getting from an online c++ compiler
// main.cpp:4:10: error: #include expects "FILENAME" or
// main.cpp: In function 'void permute(char*, int)':
// main.cpp:17:9: error: 'f' was not declared in this scope
I don't understand how to print full_string to a file!// otherwise, I know that it gives the correct output -- 90 strings.
#include <string>
#include <iostream>
#include <fstream>
#include >ios> // line 4 error
using namespace std;
char full_string[] = "112233";
[code]....
//iter_swap – it just swaps the elements pointed to by the respective pointers without changing the pointers themselves. so, it's basically equivalent to the function:
void iter_swap(char *ptr1, char *ptr2) {
char tmp = *ptr1; *ptr1 = *ptr2;
*ptr2 = tmp;
}
// min_element – finds the location of the minimum element that exists in the given range. in this case,
it is the char* pointer pointing to the location of that element. it can be implemented like:
char *min_element(char *start, char *end) {
// end is 1 beyond the last valid element
if(start == end) return end; // empty range
char *min_pos = start;
for(char *iter = start+1; iter != end; ++iter)
[code]....
View 7 Replies
View Related
Dec 26, 2013
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s="Last Assignment/n";
cout<<j[1]<<j[2]<<j[3];
I don't understand how it printing each element of whole string. Like L a s. But I did not declared array.
View 2 Replies
View Related
Apr 2, 2012
Any way to use a string to access a specific item in a matrix of int[X].
I have a program which uses enums as iterators to reference a large amount of data. To select an item in the matrix, the user will enter a string, which is also an enum, which also must serve as an iterator for something in the matrix. Here is a toybox example:
#include <iostream>
#include <string>
using namespace std;
enum NyNumbers { First, Second, Third, Forth, LAST_VALUE };
int main(int argc, char* argv[]) {
int Matrix[LAST_VALUE] = { 1, 3, 7, 12 };
[Code] .....
The idea is the user executes the program by typing "./RUN First" to print out the first element in the MyNumbers array, "./RUN Second" to access the second, and so on. I can't use static numbers for the iterator. (i.e., "./RUN 1") I must reference by enum/string.
When run, the output of this problem is thus:
====================================================================
user@debian$ ./RUN Second
Matrix[ atoi(Second) ]: 1
user@debian$
====================================================================
BTW, if I change line 12 to this
====================================================================
cout<<Matrix[ argv[1] ]<<"
";
====================================================================
The error message is this
====================================================================
user@debian$ make
g++ -g -Wall -ansi -pg -D_DEBUG_ Main.cpp -o exe
Main.cpp: In function `int main(int, char**)':
Main.cpp:12: error: invalid types `int[4][char*]' for array subscript
make: *** [exe] Error 1
user@debian$
====================================================================
Which isn't unexpected. How to input the enum as argv[1]?
View 2 Replies
View Related
May 24, 2014
I'm having trouble printing the text in between separators like commas, periods, and at signs. I'm following Jumping into C++ Chapter 19 Practice Problem 2.
This is what I have so far:
Code:
#include <iostream>#include <string>
usingnamespacestd;
int findNeedle (char separator, string inputLine) {
int needleAppearences = 0;
[Code] ....
And this was my test run output:
Enter the contact info. one, two, three, ,? , one two, th three, Program ended with exit code: 0
View 4 Replies
View Related
Jan 25, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 15
[Code]....
I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words
View 4 Replies
View Related
Feb 17, 2013
I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.
"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010
#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)
[Code] .....
View 1 Replies
View Related
May 14, 2014
How to print a string in reverse order(for example: "today is Wednesday " to "Wednesday is today"). My professor said we should begin with a null string and build it one word at a time.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int nwords(string);
[Code] .....
View 1 Replies
View Related
Feb 21, 2015
i couldnt solve the algorithm exactly. The program asks the user for a string. "Bugun h@v@ cok g'uzel" for example. then the program asks for another string. If that string doesnt exists in the main string program should say there isnt any substring. If it exist then the program should print the remaining part of main string. For example:
Write the first string: Tod@y weather is be'@utiful
write the substring : ug
>>ugun h@v@ cok guzel
write the substring :wldnqwbdbj
>>there isnt any substring
Here where i came so far
#include <stdio.h>
int main()
{
char mainstr[50],substr[50];
[Code]....
View 7 Replies
View Related
Dec 14, 2014
I'm new to c++, so how to print the contents of a map that contains a string and a class of integers for option 1. what formatting should I use?
#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include "IPHost.h"
#include "EncryptedConnection.h"
[Code] .....
View 6 Replies
View Related
Feb 23, 2015
I'm reading in a string from the command line into a char array followed by a series of ints which are read into an int array.
The command line
Code: lab3 word word word 0 0 2 3 results in the following output:
Code: Word: .N=▒
Number of Words: 0
Word: .N=▒word word word
Number of Words: 3
Num: 0
Num: 0
Num: 2
Num: 3
Here is the source code:
int main(int argc, char *argv[]){
if(argc < 2){
//command line must have at least three arguments (one
//char, one integer)
printf("Error: invalid number of arguments
[Code] .....
Where is the .N=▒ coming from?
View 3 Replies
View Related
Jan 27, 2014
For the last part of this problem, if player 2 loses the game of hangman, I need to display the letters they did get right. In order to do that, I believe that I need to traverse vector v for the elements that exist in the string hiddenword, and then print those characters that match.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int letterFill (char, string, string&);
[Code] ....
View 1 Replies
View Related
Dec 20, 2014
I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
[Code] ....
View 6 Replies
View Related
Apr 20, 2013
I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.
// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);
[Code] ....
View 3 Replies
View Related
Feb 5, 2013
A string class that finds a char in the string?
View 1 Replies
View Related
Sep 27, 2013
I am IT student and had a C++/C (oral + paper) exam today. One of the tasks was to write a 2D-Matrix (as the question said) class with following restrictions:
- No <string> header is allowed
- Only Dtor needs to be implemented
- No templates
- Following should be possible:
Code:
std::cout << mat1 + mat2 + "some randome string";
mat1 += mat2; So i did the following:
In Matrix.h i wrote: Code: Class Matrix{
int rows, cols;
char *arr[][];
[Code] .....
Now..this destructor made me loose some points since the Prof. said that it is not correct. The corrected version was:
Code:
Matrix::~Matrix(){
if(arr){
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
delete [] arr[i][j];
[Code] ....
Now, i agree on that error i made, but it is only in case we use the "new" keyword to reserve place dynamically for each string(for each char*). So this raised the question in my head about:
Since the following is allowed in C++
Code:
char* str1 = "hello";
char* str2 = "you";
arr[1][3] = str1;//arr[1][3] was initialized to "_" without new keyword
arr[6][0] = str2;//arr[6][0] was initialized to "_" without new keyword why would someone use the new keyword..
I mean like this:
Code:
arr[1][3] = new char*[sizeof("sometext1")+1];
arr[1][3] = "sometext1";
arr[6][0] = new char*[sizeof("sometext2")+1];
arr[6][0] = "sometextw";
What is happening internally in C++ in both the cases(with and without new keyword)?
View 11 Replies
View Related
Mar 27, 2013
i want to know how i can solve this question? do i need to create a class or write the program codes.
View 12 Replies
View Related
Jun 1, 2014
I just want to know the code of the program: Write code to accept matrix as aurgument and display its multiplication matrix which return its multiplication matrix.
View 1 Replies
View Related
Apr 5, 2013
I have this problem that I don't know how to sort out. I have a feeling it's really simple
#include <iostream>
#include <string>
void main () {
char test[10] = "gorilla";
char try = test[1];
cout << try;
}
I get the error:
lab4.cpp:6: error: expected primary-expression before "char"
lab4.cpp:6: error: expected `;' before "char""
View 2 Replies
View Related
Feb 27, 2012
I want to assign a matrix to submatrix of a bigger matrix.
ublas::matrix<int> A(8,5);
ublas::matrix<int> B(2,5);
for(size_t i=0;i<A.size1();++i)
for(size_t j=0;j<A.size2();++j)
A(i,j)=i*A.size2()+j+1;
for(size_t i=0;i<B.size1();++i)
for(size_t j=0;j<B.size2();++j)
B(i,j)=i*B.size2()+j+5;
ublas::matrix_range<ublas::matrix<int> > a(A,ublas::range(0,2),ublas::range(0,5));
a=B;
and it works.
but if the matrix is compressed_matrix type, there's something with it. the error log as below:
Check failed in file boost_1_48_0/boost/numeric/ublas/detail/matrix_assign.hpp at line 1078:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted
I'm not sure this is a bug or not.
View 2 Replies
View Related
Mar 4, 2013
how can I find ASCII value (0..255) of a character char in a string?
I have an array of char:
Code: char myarray[50]; and I need to have ASCII value of character eg myarray[10]. How can I do that?
View 1 Replies
View Related
Oct 19, 2013
I have some code:
char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);
After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".
Then, I use
std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);
szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.
Or is there something I'm missing? Maybe the termination character, or something.
View 1 Replies
View Related